/*************************************** *********************************/
/* Calculate the factorial of n (n <100 */
/* Use array a to store the result. each bit of the array stores one digit, and a [0] to store the number of digits of the current result */
/*************************************** *********************************/
# Include <stdio. h>
# Include <stdlib. h>
# Include <malloc. h>
# Deprecision MAX 1000
/* Known (n-1 )! In array A, evaluate K! ------- (N-1 )! Add n-1 times */
Void factorial (int * a, int N)
{
Int * B;
Int I, j, R;
Int M = A [0];
Int carry = 0;
B = (int *) malloc (sizeof (INT) * (m + 1 ));
If (! B)
{
Printf ("malloc memory error! /N ");
Exit (0 );
}
For (I = 1; I <= m; I ++)
{
B [I] = A [I];
}
For (j = 1; j <n; j ++)
{
For (I = 1; I <= m; I ++)
{
R = (I <= A [0]? A [I] + B [I]: A [I]) + carry;
A [I] = R % 10;
Carry = r/10;
}
If (carry)
{
A [++ m] = carry;
}
Carry = 0;
}
Free (B );
A [0] = m;
}
/* Output result */
Void printresult (int * a, int N)
{
Int I;
Printf ("% 4D! = ", N );
For (I = A [0]; I> 0; I --)
{
Printf ("% d", a [I]);
}
Printf ("/N ");
}
Int main ()
{
Int A [Max];
Int N, K;
Printf ("Please input the number:/N ");
Scanf ("% d", & N );
A [0] = 1;
A [1] = 1;
Printresult (A, 1 );
For (k = 2; k <= N; k ++)
{
Factorial (A, K );
Printresult (A, K );
}
Getch ();
Return 0;
}