Prerequisite: the number of endpoints is 1.
1. Each number is equal to the sum of the two numbers above it.
2. Each line of numbers is symmetric between the left and right, and gradually increases from 1.
3. There are n numbers in the nth row.
4. The number in line n is 2 ^ (n-1 ).
5. The number of m in row n is equal to the number of n-m + 1, that is, C (n-1, m-1) = C (n-1, n-m), which is a combination of numbers.
Formula of Property 6
One
6. Each number is equal to the sum of the left and right numbers in the previous row. The entire Yang Hui triangle can be written in this way. That is, the number of I in the n + 1 row is equal to the sum of the number of I-1 in the n row and the number of I, which is also one of the properties of the combination number. (For the formula, see the picture on the right)
Int n;
Scanf ("% d", & n );
Int I, j, k, a [n] [n]; // I control row, j control column
For (I = 0; I <n; I ++ ){
A [I] [0] = 1; a [I] [I] = 1; // The first and last rows are 1
}
For (I = 2; I <n; I ++ ){
For (j = 1; j <= I-1; j ++ ){
A [I] [j] = a [I-1] [j] + a [I-1] [J-1]; // equals the sum
}
}
// Print the Yang Hui triangle of the waist below
For (I = 0; I <n; I ++ ){
// K control space
For (k = 0; k <n-1-i; k ++ ){
Printf ("");
}
For (j = 0; j <= I; j ++ ){
Printf ("% 6d", a [I] [j]);
}
Printf ("\ n ");
}
Input: 10
Print:
---