int main()
{
int inputN;
cout<<"求大数阶乘,请输入一个整数:N=";
cin>>inputN;
int* const result=new int[Longth];
if (result==0)
{cout<<"数组过大,请减小Longth的值"<<endl;return 1;}
for (int i=0;i<Longth;result[i]=0,i++);
result[Longth-1]=1;
for (int ii=1;ii<=inputN;++ii) fun(result,ii);
int StartP;
for (int k=0;k<Longth;k++)
{
if(*(result+k))
{
StartP=k;
break;
}
}
cout<<"长度:"<<Longth-StartP<<endl;
for (int KK=StartP; KK<Longth;KK++) cout<<*(result+KK);
cout<<endl;
delete result;
10000! ?会有人算这样的东西么?
如果真的要算,而且数组又不够大的话,那么可以试试step by step。就是算完某一段后保存,继续下一段的计算。还有就是,不要说10000!,就是100!的结果后面已经又很多的0了,考虑怎样处理一下可能有助于减少数组的大小(想法,没有实践过)。另外,可以尝试将数看成是2^32进制的,这样也可以减少数组的大小,而且比用10进制的效率更高(不过就是更难懂)
void by(char *pf,char *ps,int n)
{
int step;
int i;
for(step=1;step<=n;step++)
{
for(i=0;i<step-1;i++)
{
add(pf,ps);
}
strcpy(ps,pf);
}
}
void turn(char *pf)
{
int f,l;
int i=0;
char *p;
char c;
for(p=pf;*p!='\0';p++)
i++;
printf("the length of the num is %d\n",i);
l=i-1;
for(f=0;f<l;l--,f++)
{
c=*(pf+f);
*(pf+f)=*(pf+l);
*(pf+l)=c;
}
}
main()
{
char pf[200]="1",ps[200]="0";
char c;
int i;
int j;
printf("gets num:");
scanf("%d",&i);
by(pf,ps,i);
printf("%s\n",pf);
printf("*************************\n");
turn(pf);
printf("%s\n",pf);
system("pause");
}