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