此题可以为杨辉三角,可以看一下这篇文章: 传送门
AC代码:
#include<iostream>using namespace std;const int N = 30;
int arr[N][N];int main()
{int n;cin >> n ;arr[1][1] = 1;for(int i=1;i<=n;i++){for(int j=1;j<=i;j++){if(j == 1 || j == i){arr[i][j] = 1;}else{arr[i][j] = arr[i-1][j-1] + arr[i-1][j];}}}for(int i=1;i<=n;i++){for(int j=1;j<=i;j++){cout << arr[i][j] << ' ';}cout << endl;}return 0;
}