c语言中100阶程是怎样写??高手拜求!!

来源:百度知道 编辑:UC知道 时间:2024/05/11 02:39:49
要是100!太大10吧!看看怎样???

用数组,下面的程序没有优化:
100!= 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

/*
* jiecheng.c
*/
#include <stdio.h>

void main()
{
char a[9999];
char b[9999];
int flag=0;
int i,j,k=0;
int N;
int tmp;

printf("Please input a Integer N(>=0)\n");
scanf("%d", &N);

memset(a,0,9999);
memset(b,0,9999);

a[0]=1;
flag=0;

for(i=0;i<=N;i++)
{
memcpy(b,a,9999);
for(j=0;j<i-1;j++)
{
k=0;
flag=0;
while(k<9999)
{
tmp = a[k]+b[k]+flag;
a[k] =tmp%10;
flag =tmp/10;
k++;
}
}
}
k=9998;
while(a[k]==0) k--;
while(k>=0)
{
printf("%d",a[k--]);
}
getch();
}