The array method is used to solve the problem that the factorial results of large numbers and huge numbers are out of bounds.
The specific algorithms have the simplest Multiplication operation ideas.
# Include <stdio. h>
Int main ()
{
Int N; // factorial size
Printf ("Enter n size :");
Scanf ("% d", & N); // receives the factorial size from the keyboard
Int A [200]; // make sure that the array that saves the final calculation result is large enough
Int carry; // carry
Int digit = 1; // number of digits
A [0] = 1; // initialize the result to 1 first
Int temp; // the product of any element of a factorial and a certain value of a temporary result
For (INT I = 2; I <= N; ++ I) // start the factorial. The factorial element starts to appear in sequence from 2"
{
// Multiply each of the temporary results by the factorial element based on the basic multiplication algorithm.
For (Int J = 1, carry = 0; j <= digit; ++ J)
{
Temp = A [J-1] * I + carry; // One of the corresponding factorial is multiplied by one of the current temporary results (plus carry)
A [J-1] = TEMP % 10; // update the bitwise information of the temporary result
Carry = temp/10; // check whether there is an advance
}
While (carry) // if there is an increment
{
A [++ digit-1] = carry % 10; // Add a new digit to add information. Increase by 1
Carry/= 10; // you can check whether the carry can be carried.
}
}
Printf ("Result:/n % d! = ", N); // display the result
For (INT I = digit; I> = 1; -- I)
{
Printf ("% d", a [I-1]);
}
Return 0;
}