文章
105
粉丝
69
获赞
117
访问
57.3k
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int n;
int res[N][N];
void get_triangle()
{
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= i; j ++)
{
if(j == 1 || j == i) res[i][j] = 1;
else res[i][j] = res[i - 1][j] + res[i - 1][j - 1];
}
}
for(int i = 2; i <= n; i ++)
{
for(int j = 1; j <= i; j ++)
cout << res[i][j] << " ";
cout << endl;
}
}
int main()
{
while(cin >> n)
{
memset(res, 0, sizeof res);
get_triangle();
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发