/* 05-06-10 21:40
Recursively print the Yang Hui triangle: here you need to know a conclusion:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
I (> = 0) indicates the row number, and J (> = 0) indicates the number of locations as follows:
The first number of rows in 4th is 3: 3! /(2! * (3-2 )!) = 3: The number starts from 0, and the industry starts from 0.
The number of 4th rows is 3: 3! /(0! * (3-0 )!) = 1
Yang Hui triangle meets a combination formula: n! /(! M *! (N-m) using this formula, we can find each number.
The formula is as follows:
Yang Hui triangle number at a certain position = factorial of the current number of rows (starting from 0)/(factorial composed of the number of column positions starts from 0) * (number of rows-factorial of the number of columns ))
*/
# Include <iostream>
Using namespace STD;
Int fun (int n) // n indicates the number of rows
{
If (n = 0)
{
Return 1;
}
Else
{
Return N * Fun (n-1 );
}
}
Int main ()
{
Int N;
Int I, J;
Int C; // Save the temporary variable of the Yang Hui triangle
Int curline; // The factorial of the current row, starting from 0.
Int backline; // number of rows-factorial composed of column locations
Int position; // The factorial of the nth position of the row
Cout <"Enter the number of lines in the Yang Hui triangle :";
Cin> N;
For (I = 0; I <= N; I ++)
{
For (int K = I; k <n; k ++) cout <"; // output the leading space (2), which should be well matched with the trailing space
For (j = 0; j <= I; j ++) // equal sign
{
Curline = fun (I); // factorial of the current number of rows, starting from 0
Backline = fun (I-j); // number of rows-factorial composed of column locations
Position = fun (j); // factorial of the nth position of the row
C = curline/(backline * position); // The value of the Yang Hui triangle.
Cout <C <""; // five spaces
}
Cout <Endl; // output line feed processing
}
Cout <Endl;
System ("pause ");
Return 0;
}