提交时间:2024-08-21 16:28:35
运行 ID: 180604
#include<bits/stdc++.h> using namespace std; int n, i, j, a[18][18]; int main(){ cin >> n; memset(a, 0, sizeof(a)); if(n == 1){ cout << 1; return 0; } a[1][1] = 1; for(i = 2; i <= n; i++){ for(j = 1; j <= i; j++){ if(j == 1 || j == i){ a[i][j] = 1; } else { a[i][j] = a[i - 1][j] + a[i - 1][j - 1]; } } } for(i = 1; i <= n; i++){ for(j = 1; j <= i; j++){ cout << a[i][j] << " "; } cout << endl; } return 0; }