#include<iostream.h>
void main()
{
int result[10000];
int p=0,i;
int ininum=0;
char ini[10];
int temp;
memset(result,0,sizeof(p)*10000);
cout<<"please input the initial number"<<endl;
cin>>ini;
for( i=0,p=strlen(ini)-1;i<strlen(ini);p--,i++)
{
result[p]=ini[i]-'0';
ininum=ininum*10+result[p];
}
ininum--;
p=strlen(ini)-1;
int jin,high,max;
max=p;
for(;ininum>0;ininum--)
{
for(i=0;i<=p;i++)
result[i]*=ininum;
for(i=p,high=i;i>=0;i--,high=i)
{
while(result[high]>9)
{
jin=result[high]/10;
result[high]=result[high]%10;
high++;
result[high]+=jin;
if(high>max)
max=high;
}
}
p=max;
}
for(int j=max;j>=0;j--)
cout<<result[j];
}
----------------解决方案--------------------------------------------------------
改好了 至少可以算 20000 以内的了
#include<iostream.h>
#include"conio.h"
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void main()
{
FILE *fp;
int result[100000];
int p=0,i;
int ininum=0;
char ini[10];
int temp;
memset(result,0,sizeof(p)*100000);
cout<<"please input the initial number"<<endl;
cin>>ini;
for( i=0,p=strlen(ini)-1;i<strlen(ini);p--,i++)
{
result[p]=ini[i]-'0';
ininum=ininum*10+result[p];
}
ininum--;
p=strlen(ini)-1;
int jin,high,max;
max=p;
for(;ininum>0;ininum--)
{
for(i=0;i<=p;i++)
result[i]*=ininum;
for(i=p,high=i;i>=0;i--,high=i)
{
while(result[high]>9)
{
jin=result[high]/10;
result[high]=result[high]%10;
high++;
result[high]+=jin;
if(high>max)
max=high;
}
}
p=max;
}
// for(j>=0;j--)
// cout<<result[j];
if((fp=fopen("result.txt","a+"))==NULL)
{
cout<<"can't open the file!"<<endl;
exit(0);
}
int j=max;
while(j>=0)
{
fputc(result[j]+'0',fp);
j--;
}
fclose(fp);
}
----------------解决方案--------------------------------------------------------