行是用户输入的。
cout << "Input the number of rows: ";
cin >> row;
column=row;
int triangle[row][column];
for (i=0;i<=row;i++){
for (j=0;j<=column;j++){
triangle[i][j]=0;
}
}
for (i=0;i<=row;i++){
for (j=0;j<=i;j++){
if (j==0 || j==i){
triangle[i][j]=1;
} else {
triangle[i][j]=triangle[i-1][j]+triangle[i-1][j-1];
}
}
}
cout << "Pascals triangle with " << row << " rows.";
for (i=0;i<=row;i++){
for (j=0;j<=i;j++){
cout << triangle[i][j] << "\t";
}
cout << endl;
}
当行为 7 时,它确实给出了正确的结果,但是当输入的行大于 8 时,它会以某种方式崩溃。