楊輝三角杭電2032

6300 ワード

11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1
 
 
Input
入力データには複数のテストインスタンスが含まれ、各テストインスタンスの入力には正の整数n(1<=n<=30)のみが含まれ、出力する楊輝三角の層数を表す.
 
 
Output
各入力に対応して、対応する層数の楊輝三角を出力し、各層の整数間をスペースで区切り、各楊輝三角の後ろに空行を追加します.
 
 
Sample Input
2 3
 
 
Sample Output
1 1 1 1 1 1 1 2 1
 
#include<stdio.h>
int main() { int n,i,j,a[31][31]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { for(j=0;j<=i;j++) { if(j==0||i==j)
                    a[i][j]=1; else
                        a[i][j]=a[i-1][j]+a[i-1][j-1]; } } for(i=0;i<n;i++) { for(j=0;j<=i;j++) { if(i==j)
                    printf("%d",a[i][j]); else
                    printf("%d ",a[i][j]); }
            printf("
"
); } printf("
"
); } return 0; }