为了求一个很大的数(如100!)的值,我设计了这样的一道算法,望大家看后多多指教!
#include<stdio.h>
#include<math.h>
void main()
{
long a[256],b,d;
int m,n,i,j,r;
printf("请输入N的值:");
scanf("%d",&n);
m = log(n)*n/6+2;
a[1] = 1;
for(i=2;i<=m;i++)
a[i] = 0;
d = 0;
for(i=2;i<=n;i++)
{
for(j=1;j<=m;j++)
{
b = a[j]*i + d;
a[j] = b % 1000000;
d = b / 1000000;
}
if(d != 0)
{
a[j] = d;
m++;
}
}
for(i=m;i>=1;i--)
if(a[i] == 0)
continue;
else
{
r = i;
break;
}
printf(" %d != ",n);
printf(" %d",a[r]);