Description
Output the Yang Hui triangle in the lower left triangle.
Input
Enter a positive integer n (n≤10).
Output
Outputs n rows Yang hui triangles. Each number has a width of 4.
"Input Sample"
5
"Output Sample"
1
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
Prompted
Output the Yang Hui triangle in the form of the lower left triangle, using the main diagonal as the dividing line between 0 elements and non-0 elements. Suppose I and J represent the row and column subscripts of a two-dimensional array, respectively.
The elements on the ① triangle two waist are 1. Two waist one for the No. 0 column, one for the main diagonal.
② the remaining elements of the triangle are equal to the sum of the two shoulder elements (the sum of the previous column element and the same column element on the previous row) except for the two waists.
Source
"The basis of program design--take C as an example," the 6th chapter on the computer experimental question 8.
#include <stdio.h>
int main () {
int n,i,j,a[10][10];//first became a[10], so the subscripted value is neither array nor pointer nor vector errors
//Hints I subscript error
scanf ("%d", &n);
for (i=0;i<n;i++) {for
(j=0;j<n;j++) {
if (j==0| | I==J)
a[i][j]=1;
else{
a[i][j]=a[i-1][j]+a[i-1][j-1];}}
}
for (i=0;i<n;i++) {
for (j=0;j<n;j++) {
if (i>=j)
printf ("%4d", A[i][j]);//Enter Forgot to add
}
printf ("\ n");}
}