Factorial is an operational symbol invented by Kiston Kaman (Christian kramp,1760~1826) in 1808 and is a mathematical term. A positive integer.
factorialEnglish
factorial) is the product of all positive integers less than and equal to the number, and has a 0 factorial of 1. The factorial writing n! of the natural number N. In 1808, Kiston Kaman introduced this notation. namely N!=1x2x3x...xn. Factorial can also be defined recursively: 0!=1,n!= (n-1)!xn.
How to calculate factorial
Factorial means multiplying from 1 times 2 multiplied by 3 times 4 to the required number.
For example, the required number is 4, then the factorial formula is 1x2x3x4, the resulting product is 24,24 is the factorial of 4. For example, the number required is 6, then the factorial is 1x2x3x. X6, the resulting product is 720,720 is the factorial of 6. For example, the required number is n, then the factorial formula is 1X2X3X...XN, the resulting product is the factorial of X,x is n.
How factorial is represented
When expressing factorial, use "! "To express. such as the factorial of X, is expressed as x!
His principle is to push back, such as, for example, 10 factorial =10*9 factorial (later use! to represent factorial) so 9!=? , 9!=9*8!,8!=8*7!,7!=7*6!,6!=6*5!,5!=5*4!,4!=4*3!,
What is the factorial of 3!=3*2!,2!=2*1!,1? is 1 1!=1*1, the mathematician rules, 0!=1, so 0!=1! then projections forward, the formula for n! (n! is the factorial of the current number) =n (current number) * (n-1)! (one less than he's a number N-1 factorial put the formula listed like a post-push, only 1!) is 1, so start with 1 and know 3! You know, 2! You need to know 1! But must be from 1! Start reckoning so like after push, if the program algorithm can be solved with a function, and nested call sub-function,, the number into the formula, 1!=1*1 2!=2*1 (1!) 3!=3*2 (2!) 4=4*6 (3!), if programmed, how to solve the problem of the formula?
First define the algorithm
Algorithm, 1, define function, find factorial, define function fun, parameter value N, (#include <stdio.h>
Long Fun (int n)//long is a length integer, because 20! It's a lot bigger than trillion billion.
(mathematician defines mathematician definition, 0!) =1, so 0! =1! , the factorial of 0 and 1 has no practical significance)
2, the function body is judged, if this number is greater than 1, then execute if (n>1) (back to the calculation, this number is 10 to ask it!), to start with the factorial value of 2, so the number of times to execute the formula is defined as 9, especially in this case, the current first write code execution, already counted once)
To find the n factorial of this number (the formula is, n! =n* (n-1)! , and back a value,
Return (n (n-1);(This formula, first of all, this formula is the factorial of 10, but the factorial of 10 requires, 9 factorial, 9 factorial We do not know, so we will 10 minus 1, that is, n-1 as a new factorial, the newly called Fun function, Ask for its factorial then return this value to Fun (n-1), and then execute n the value it returns, actually this formula is the result of calling the fun function, the value of the function is the value returned by return, (n-1) is the parameter, and so on ... One-value nested call fun function,
To the value of the n-1 = 1,
Note: the fun () function is running 9 times at this time, and it is called a few fun functions. 8 times the function, so, n-1 executed 9 times, N-1=1, n=2 has been called to be able to ask 2 times the order value
What is factorial