![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <iostream> #define N 15 using namespace std; int a[N][N]; void yanghui(int n) { int i,j; for(i=0;i<n;i++) a[i][0]=a[i][i]=1; for(i=2;i<n;i++) for(j=1;j<i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j]; } int main() { int i,j,n; cin>>n; yanghui(n); for(i=0;i<n;i++) { for(j=0;j<=i;j++) cout<<a[i][j]<<" "; cout<<"\n"; } return 0; }
#include <iostream>
#define N 15
using namespace std;
int a[N][N];
void yanghui(int n)
{
int i,j;
for(i=0;i<n;i++) a[i][0]=a[i][i]=1;
for(i=2;i<n;i++)
for(j=1;j<i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j];
}
int main()
{
int i,j,n;
cin>>n; yanghui(n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
cout<<a[i][j]<<" ";
cout<<"\n";
}
return 0;
}