大整数案例
输入不超过1000的正整数n,输出阶乘,用一位数组装结果(倒序)
input 30
output 265252859812191058636308480000000
1 #include<stdio.h> 2 #include<string.h> 3 const int MAX=3000; 4 int f[MAX]; 5 int main() 6 { 7 int i,j,n; 8 scanf("%d",&n); 9 memset(f,0,sizeof(f)); 10 f[0]=1; 11 for(i=2;i<=n;i++) 12 { 13 int c=0; 14 for(j=0;j<MAX;j++) 15 { 16 int s=f[j]*i+c; 17 f[j]=s%10; 18 c=s/10; 19 } 20 } 21 for(j=MAX-1;j>=0;j--) 22 { 23 if(f[j]) 24 break; 25 } 26 for(i=j;i>=0;i--) 27 printf("%d",f[i]); 28 printf("\n"); 29 return 0; 30 }