/*我的程序只能算到100以内的阶乘,不是因为精度不够,是因为程序有点平常化,大家给点建议吧,尚在改进中...*/
#include<stdio.h>
#define N 200
#include<string.h>
struct Big_number{
int data[N];
int len;
};
void mul_big_number(Big_number &a,int num)
{
int i,t=0,s;
for(i=0;i<a.len;i++)
{
s=a.data[i]*num+t;
a.data[i]=s%10;
t=s/10;
}
if(t>0)
{
a.data[i]=t;
a.len++;
}
}
void Add_big_number(Big_number &a,Big_number &b)
{
int carry,i,len,temp;
len = a.len > b.len ? a.len : b.len;
carry = 0;
for (i = 0;i < len;i++)
{
if(i>=a.len)
{
a.data[i]=0;
}
if(i>=b.len)
{
b.data[i]=0;
}
temp = a.data[i] + b.data[i] + carry;
carry = temp / 10;
a.data[i] = temp % 10;
}
if (carry != 0)
{
a.len = len + 1;
a.data[len] = carry;
}
else
{
a.len = len;
}
}
void Display(Big_number a)
{
int i;
for(i=a.len-1;i>=0;i--)
{
printf("%d",a.data[i]);
}
printf("\n");
}
int main()
{
Big_number a,b,c;
int i,j;
a.data[0]=1;
a.len=1;
for(i=2;i<=100;i++)
{
for(j=0;j<a.len;j++)
{
b.data[j]=a.data[j];
c.data[j+1]=a.data[j];
}
b.len=a.len;
c.len=a.len+1;
c.data[0]=0;
if(i%10)
{
mul_big_number(b,i%10);
}
else
{
mul_big_number(b,i%10);
}
//Display(b);
if(i/10)
{
mul_big_number(c,i/10);
//Display(c);
Add_big_number(b,c);
}
for(j=0;j<b.len;j++)
{
a.data[j]=b.data[j];
}
a.len=b.len;
memset (b.data,0,sizeof (int) * N);
memset (c.data,0,sizeof (int) * N);
// Display(a);
}
for(i=a.len-1;i>=0;i--)
{
printf("%d",a.data[i]);
}
printf("\n");
return(0);
}