求一份用c++编写的杨辉三角
我刚学c++没多久,觉得编程特难
程序代码:
#include <iostream> using namespace std; int main() { const int num = 8; int i, j; int a[num][num]; for (i=0; i<num; i++) { for (j=0; j<=i; j++) { if (j==0 || j==i) { a[i][j] = 1; } else { a[i][j] = a[i-1][j-1] + a[i-1][j]; } cout<<a[i][j]<<"\t"; } cout<<"\n\n"; } return 0; } /* 输出结果为: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 Press any key to continue */