Yang Hui triangle Hangzhou Electric 2032

Source: Internet
Author: User

1
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
1 5 10 10 5 1

Input data contains multiple test instances, and each test instance input contains only one positive integer n (1<=n<=30), representing the number of layers of the Yang Hui triangle that will be output.

Output corresponds to each input, export the Yang Hui triangle of the corresponding number of layers, separated by a space between the integers of each layer, and a blank line behind each Yang Hui triangle.

Sample Input2 3

Sample Output11 111 11 2 1

#include <stdio.h>intMain(){intN,I,J,A[ to][ to]; 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;ElseA[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]);ElsePrintf("%d",A[I][J]); }Printf("\ n"); }Printf("\ n"); }return0;}

Yang Hui triangle Hangzhou Electric 2032

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.