打印杨辉三角
杨辉三角
#include <stdio.h>
int main(void)
{
int high, row, col;
int a[10][10];
scanf("%d", &high);
//存放数值
for(row = 0; row < high; row++)
{
a[row][0] = 1;
a[row][row] = 1;
}
for(row = 2; row < high; row++)
{
for(col = 1; col < row; col++)
{
a[row][col] = a[row-1][col] + a[row-1][col-1];
}
}
//输出
for(row = 0; row < high; row++)
{
for(col = 0; col <= row; col++)
printf("%-3d", a[row][col]);
putchar('\n');
}
return 0;
}