杨辉三角(presentation error)

打印杨辉三角前n行


Sample Input
6


Sample Output
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1




 

#include <stdio.h>
int main()
{
    int i,j,s=0,k,n,e;
    while(scanf("%d",&n)!=EOF)
    {
    for(i=1;i<=n;i++)
    {
        k=1;e=0;
        for(j=1;j<=i;j++)
        {
            if(e==0)
                printf("%d",k);
            else
                printf(" %d",k);
            k=k*(i-j)/j;
            e++;
        }
        puts("");
    }
    }
    return 0;
}

 

posted @ 2018-03-27 15:20  ~~zcy  阅读(160)  评论(0编辑  收藏  举报