循环后更改了C ++参数

我用C ++创建了一个代码来计算组合,但是在使用参数'n'的for循环之后,它变成了0,而我的其他参数'm'变成了88。有人可以告诉我我的代码有什么问题吗?谢谢。

#include <bits/stdc++.h>

using namespace std;

long binomialCoefficient(int n, int m) {

    long bc[n+1][m+1];

    for (int i = 0; i <= n; i++) {
        bc[i][0] = 1;
        bc[i][i] = 1;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < i; j++) {
            bc[i][j] = bc[i-1][j-1]+bc[i-1][j];
        }
    }
    cout << n << " " << m << "\n";
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            cout << bc[i][j] << " ";
        }
        cout << "\n";
    }

    cout << n << " " << m << "\n";
    return bc[n][m];
}

int main() {
    int x = 8;
    int y = 3;

    cout << binomialCoefficient(x, y) << " possible ways\n";
}

在此循环后,参数已更改:

for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
        bc[i][j] = bc[i-1][j-1]+bc[i-1][j];
    }
}
评论