Topic 1073: Yang Hui triangles
time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:3239
Resolution:1399
-
Title Description:
-
Enter an n value and use a recursive function to find the values at each position in the Yang Hui Triangle.
-
Input:
-
An integer number greater than or equal to 2 n
-
Output:
-
The topic may have multiple sets of different test data, for each set of input data,
Output the Yang Hui triangle of the corresponding input n as required by the topic.
-
Sample input:
-
6
-
example Output:
-
1 11 2 11 3 3 11 4 6 4 11 5 Ten 5 1
#include <stdio.h>int a[1000][1000];int yang (int x,int y) { if (a[x][y]==0) { if (x==y| | y==1) a[x][y]=1; else A[x][y]=yang (x-1,y) +yang (x-1,y-1); } return a[x][y];} int main (int argc, char *argv[]) { int n; while (~SCANF ("%d", &n)) { if (n<2) continue; for (int i=2;i<=n;++i) { for (int j=1;j<=i-1;++j) { printf ("%d", Yang (i,j)); } printf ("%d\n", Yang (i,i)); } } return 0;} /************************************************************** problem:1073 user:kirchhoff Language:c result:accepted time:10 ms memory:4820 kb********************************************* *******************/
Nine degree OJ 1073 Yang Hui Triangle