[蓝桥杯]基础练习 杨辉三角形
程序员文章站
2022-05-11 22:27:33
...
#include<iostream>
#include<cstring>
using namespace std;
int nums[40][40]={0};
int main()
{
int n = 0;
cin>> n;
for(int i = 0; i <= n; i++)
{
nums[i][0] = 1;
}
cout<<1<<endl;
for(int i = 1; i < n; i++)
{
cout<<1<<" ";
for(int j = 1; j <= i; j++)
{
nums[i][j] = nums[i-1][j-1] + nums[i-1][j];
cout<<nums[i][j]<<" ";
}
cout<<endl;
}
return 0;
}