C语言 输出杨辉三角前十行,以正三角形图形输出

2024-11-15 07:09:53
推荐回答(1个)
回答1:

标准的三角形,希望采纳
#include
void main()
{
int y[11][11], i, j;
y[0][0] = 1;
y[1][0] = y[1][1] = 1;
for (i = 2; i <= 10; i ++)
{
y[i][0] = y[i][i] = 1;
for (j = 1; j < i; j ++)
y[i][j] = y[i-1][j] + y[i-1][j-1];
}

for (i = 0; i <= 10; i ++)
{
for (j = 0; j < (10 - i)*2; j ++)
printf(" ");

for (j = 0; j <= i; j ++)
printf("%4d", y[i][j]);
printf("\n");
}
}