Home > Back-end >  PTA print Yang hui triangle (10 points) subject requirements, in accordance with the prescribed form
PTA print Yang hui triangle (10 points) subject requirements, in accordance with the prescribed form

Time:12-11

Their compiled , a custom for easier function of factorial
Subject requirements, in accordance with the prescribed format printing first N rows of Yang hui triangle,
Input format:
N given in the input in a row (1 N 10 or less or less),
The output format:
Triangle is to the format of the output first N rows of Yang hui triangle, each number four fixed,
Input the sample:
6
The output sample:
1
1 1
1 2 1
3 3 1
1 4 6 4 1
5 10 10 1
The following code
 
# include
#include
Int fn (int x);
Int main () {
Int n, I, j;
The scanf (" % d ", & amp; n);
for(i=0; i<=n - 1; I++) {
For (int t=1; T<=n - 1 - I; T++)
Printf (" ");
for(j=0; j<=i; J++) {
Printf (" % 4 d ", fn (I)/(fn (j) * fn (I - j)));
}
printf("\n");
}
return 0;
}
Int fn (int x) {
Int s=1;
for(int i=1; i<=x; I++) {
S *=I;
}
Return s;
}
  • Related