文章
84
粉丝
408
获赞
33
访问
877.7k
#include<iostream>
using namespace std;
int main()
{
int tr[21][21];
for (int i = 1; i <= 20; i++) {
for (int j = 1; j <= 20; j++) {
if (j == 1 || i == j) {
tr[i][j] = 1;
}
else {
tr[i][j] = tr[i-1][j-1] + tr[i-1][j];
}
}
}
int n;
while (1) {
cin >> n;
if (n == 0) {
break;
}
else if (n < 0 || n > 20) {
continue;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
cout << tr[i][j] << " ";
}
cout << tr[i][i] << endl;
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发