Problem Description
输出杨辉三角前n行。
Input
输入一个数n(n <= 9)
Output
输出杨辉三角前n行。(注意行末不能有多余的空格,数字以%3d的格式输出)
Sample Input
3
4
Sample Output
1
1 1
1 2 1 1
1 1
1 2 1
1 3 3 1
HINT
注意有多组输入。每组测试数据后面输出一个空行。
while(scanf("%d",&n) != EOF)
{
......
}
#include<stdio.h>
int main()
{
int n,i,j;
int a[][];
a[][]=a[][]=a[][]=;
while(scanf("%d",&n)!=EOF)
{
for(i=;i<n;i++)
{
for(j=;j<=i;j++)
{
if(j== || i==j)
a[i][j]=;
else
a[i][j]=a[i-][j-]+a[i-][j];
}
} for(i=;i<n;i++)
{
for(int k=;k<(n-i-);k++)
{
printf(" ");
}
for(j=;j<=i;j++)
{
if(j==)
{
printf("%3d",a[i][j]);
}
else
{ printf("%4d",a[i][j]);
} }
printf("\n");
}
printf("\n");
} return ;
}