You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
529 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int a[N][N];
int n;
int main() {
cin >> n;
//遍历每一行
for (int i = 0; i <= n - 1; i++) {
//遍历每一列
for (int j = 0; j <= i; j++) {
//第一列最后一列都是1
if (j == 0 || j == i) a[i][j] = 1;
//递推式
else a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}