关于n的阶乘的一道题
当n<=33时运行正常,当n>=34时就错误了~~代码:
#include <stdio.h>
long a[10000];
void fun(int n);/*计算n的阶乘*/
int main(void)
{
int n;
printf("please input the number n\n");
scanf("%d",&n);
fun(n);
return 1;
}
void fun(int n)
{
int count=0;
int i;
int j;
int k;
int inc;
for(i=0;i<10000;i++)
a[i]=0;
a[0]=1;
for(i=1;i<=n;i++)
{
inc=0;
for(j=0;j<=count;j++)
{
a[j] = i * a[j] + inc;
inc = a[j] / 10;
a[j] = a[j] % 10;
}
if(inc > 0)
{
count++;
a[count] = inc;
}
for(k=count;k>=0;k--)
printf("%ld",a[k]);
printf("\n");
}
for(i=count;i>=0;i--)
printf("%ld",a[i]);
printf("\n");
}
编译环境为GCC