思路:
让二维数组初始化为0, pas[0][0] = 1, 然后就能模拟了. pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
1 #include
2 using namespace std;
3
4 int pas[50][50]{0};
5
6 int main()
7 {
8 ios::sync_with_stdio(false);
9 cin.tie(0);
10
11 int n;
12 cin >> n;
13 pas[0][0] = 1;
14 for (int i = 1; i <= n; i++) {
15 for (int j = 1; j <= i; j++) {
16 pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
17 if (j == i)
18 cout << pas[i][j] << endl;
19 else
20 cout << pas[i][j] << ' ';
21 }
22 }
23
24 return 0;
25 }
标签:pas,int,练习,cin,50,蓝桥,杨辉三角
来源: https://www.cnblogs.com/AntonLiu/p/12249031.html