#include <stdio.h>
#include <math.h>
//程序以四个数字为一组
//返回值为结果的位数
int factorial(int n,long *result)
{
int i,j; //循环变量
int c; //进位数
int m = 0; //记录数组的下标
int w; //记录结果的位数
result[0] = 1;
for(i = 1; i <=n; i++) //循环n个数
{
c = 0;
for(j = 0; j <= m; j++) //循环已有的数组
{
result[j] = result[j] * i + c;
c = result[j] / 10000; //进位
result[j] = result[j] % 10000;
}
if(c > 0)
{
m++;
result[m] = c;
}
}
w = (int)(m * 4 + log10(result[m]) + 1); //计算结果的位数
printf("%ld",result[m]);
for(i=m-1;i>=0;i--)
{
printf("%4.4ld",result[i]);
}
return w;
}
n 的阶乘 C 语言版(大数)
最新推荐文章于 2021-11-13 09:49:07 发布