Input
Input data comprising a plurality of test cases, each test case comprising input only a positive integer n (1 <= n <= 30), Pascal's triangle represents the number of layers to be output.
Output
Pascal's triangle corresponding to each input, output a corresponding number of layers, each layer between integer separated by a space, each of Pascal's triangle behind a blank line.
Sample Input
2 3
Sample Output
1 1 1
1 1 1 121
At first glance find it difficult to do, in fact, as long as the entire Pascal's Triangle written, how many layers to him, how many layers you print.
code show as below:
#include <stdio.h> int a[35][35]; int main() { int i,j,n; for(i = 0;i < 35;i++) for(j = 0;j <= i;j++) a[i][j] = 1; for(i = 2;i < 35;i++) for(j = 1;j < i;j++) a[i][j] = a[i-1][j-1]+a[i-1][j]; while(scanf("%d",&n) != EOF){ for(i = 0;i < n;i++) for(j = 0;j <= i;j++) printf(j==i ? "%d\n" : "%d ",a[i][j]); printf("\n"); } return 0; }
In order to avoid the risk of cross-border, usually the size of the array to open bigger, it should be ACMer have basic knowledge of it.
Then late that looks better (on the kind of junior high school book) Pascal's Triangle try to print it out. I hope not pigeon.