For a large number of operations, may exceed the range of int, or even long, for this, you can use an array to store large numbers, the following code is to ask for 1000 of the number of factorial code, the code is as follows:
#include <stdio.h>#include<string.h>Const intmax= the;intMain () {intf[ the];//Store the final result intI,j,n,c,tem; Memset (F,0,sizeof(f)); scanf ("%d",&N); f[0]=1; for(i=2; i<=n;i++) {C=0; for(j=0; j<max;j++) {tem=i*f[j]+C; C=tem/Ten; F[J]=tem%Ten; } } for(j=max-1; j>=0; j--) if(f[j]!=0) Break; for(i=j;i>=0; i--) printf ("%d", F[i]); printf ("\ n"); return 0;}
The understanding of this code can be explained by the simplest examples.
For example, using an int array to store the result, the array length is 4, and the array name is a.
In the 45*33 operation, the written calculation method of using primary school is as follows:
In the computer language, we calculate this, first a[0]=5,a[1]=4,a[3]=0,a[4]=0;
33*a[0]=135, A[0] is assigned a value of 5, carry is c=13
Step Two
33*a[1]+c=148, A[1] is assigned a value of 8, carry is c=14
Step Three
33*a[2]+c=14, A[2] is assigned a value of 4, carry is c=1
Fourth Step
33*a[3]+c=1, now the A[3] assignment is 1, the operation succeeds!
The exact value of factorial in C language