Problem Description
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
上面的图形熟悉吗?它就是我们中学时候学过的杨辉三角。
Input
输入数据包含多组测试数据。
每组测试数据的输入只有一个正整数n(1≤n≤30),表示将要输出的杨辉三角的层数。
输入以0结束。
Output
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
Example Input
2
3
0
Example Output
1
1 1
1
1 1
1 2 1
Hint
Author
ZJGSU
#include<stdio.h>
int main()
{
int n,i,j;
while(scanf("%d",&n) != EOF && n != 0)
{
int a[100][100] = {0};
for(j = 0; j < n; j++)
a[j][0] = 1;
for(i = 1; i < n; i++)
for(j = 1; j < n; j++)
a[i][j] = a[i-1][j] + a[i-1][j-1];
for(i=0;i<n;i++)
{
for(j = 0;j <= i; j++)
{
printf("%d%c", a[i][j], j == i? '\n':' ');
}
}
printf("\n");
}
return 0;
}