#include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[n][n];
int i = 0;
int j = 0;
for (i = 0; i < n; i++)
{
//首先让每行的第一列和最后一列都为1
a[i][0] = 1;
a[i][i] = 1;
for (j = 1; j <i; j++)
{
//然后根据杨辉三角的规律计算出每行的其余几个元素
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
{
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
02-12
2497
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-07
1116
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)