Wuhan University of Science and Technology acm:1001: Chinese Edition C language Programming tutorial (second edition) Exercise 6.7

Source: Internet
Author: User

Problem Description

The output Yang Hui the first n rows of the triangle.

Input

Enter a number n (n <= 9)

Output

The output Yang Hui the first n rows of the triangle. (Note that there is no extra space at the end of the line, the number is output in%3d format)

Sample Input
34
Sample Output
      1    1   1  1   2   1        1      1   1    1   2   1  1   3   3   1
HINT

Note that there are multiple sets of inputs. Output a blank line after each set of test data.

while (scanf ("%d", &n)! = EOF)

{

......

}

1#include <stdio.h>2 intMain ()3 {4     intn,i,j;5     inta[Ten][Ten];6a[0][0]=a[1][0]=a[1][1]=1;7      while(SCANF ("%d", &n)! =EOF)8     {9          for(i=2; i<n;i++)Ten         { One              for(j=0; j<=i;j++) A             { -                 if(j==0|| i==j) -a[i][j]=1; the                 Else -a[i][j]=a[i-1][j-1]+a[i-1][j]; -             } -         } +  -          for(i=0; i<n;i++) +         { A              for(intk=0;k< (n-i-1); k++) at             { -printf"  "); -             } -              for(j=0; j<=i;j++) -             { -                 if(j==0) in                 { -printf"%3d", A[i][j]); to                 } +                 Else -                 { the  *printf"%4d", A[i][j]); $                 }Panax Notoginseng                  -                  the             } +printf"\ n"); A         } theprintf"\ n"); +     } -      $     return 1; $}

Wuhan University of Science and Technology acm:1001: Chinese Edition C language Programming tutorial (second edition) Exercise 6.7

Related Article

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.