求大数阶乘(万进制方法)
#include<stdio.h>
#include<string.h>
int main() {
int n, t, i, j, k, f, a[10000];
while(scanf("%d",&n) != EOF) {
memset(a, 0, sizeof(a));//初始化0;
t = 1;
a[1] = 1;
for(i = 1; i <= n; i++) { //n的阶乘,从1到n
k = 0;
for(j = 1; j <= t; j++) { //数组存储(四位一存);
a[j]=a[j]*i+k;
k=a[j]/10000;
a[j]=a[j]%10000;
}
if(k != 0) { //数组下标增加 (到达四位一移);
t++;
a[t]=k;
}
}
printf("%d",a[t]);//最高位不需要考虑是否前导0;
for(i = t-1; i > 0; i--) {
printf("%04d",a[i]);//四位一存则要考虑前导0的清楚
}
printf("\n");
}
return 0 ;
}