#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <assert.h>
#define Rows 100
#define Cols 100
int main()
{
int arr1[Rows][Cols] = { 0 };
int num = 0;
scanf("%d", &num);
assert(num < Rows);
for (int i = 0; i < num; i++)
{
for (int j = 0; j <= i; j++)
{
if (j == 0 || j == i)
{
arr1[i][j] = 1;
}
else
{
arr1[i][j] = arr1[i - 1][j - 1] + arr1[i - 1][j];
}
}
}
for (int i = 0; i < num; i++)
{
int blank = num - i - 1;
while (blank--)
{
printf(" ");
}
for (int j = 0; j <= i; j++)
{
printf("%2d ", arr1[i][j]);
}
printf("\n");
}
return 0;
}
【C语言】每日一代码:杨辉三角
最新推荐文章于 2024-08-26 00:02:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)