杨辉三角形
程序员文章站
2022-04-01 18:33:35
...
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i, j, a[999] = { 0,1 }, n = 0, x, y;
while (n < 1 || n>999)
{
printf("请输入杨辉三角形的行数:");
scanf_s("%d", &n);
}
for (i = 1; i <= n; i++)
{
x = 0;
for (j = 1; j <= i; j++)
{
y = a[j];
a[j] = x + y;
x = y;
printf("%d", a[j]);
}
printf("\n");
}
system("pause");
return 0;
}