我这么一个小程序为什么运行起来很慢呢?
天怒-无情 2009-07-04 11:17:04 #include<iostream.h>
float jiechen(float n);
void jiecheng(void);
void jiechenhe(void);
void sumjc(void);
void main()
{
int gn;
do
{
cout<<"please choosing what you want to do:"<<"\n";
cout<<"1:"<<"\t"<<"1!+2!+...+n!"<<"\n";
cout<<"2:"<<"\t"<<"1+E(-1)^(n+1)((x^n)/n!)"<<"\n";
cout<<"3:"<<"\t"<<"x!"<<"\n";
cout<<"0:"<<"Eixt"<<"\n";
cout<<"your choose is:";
cin>>gn;
switch(gn)
{
case 0:
{
cout<<"thank you for yours:";
}
break;
case 1:
{
jiechenhe();break;
}
case 2:
{
sumjc();
}
break;
case 3:
{
jiecheng();
}
break;
default:cout<<"input error"<<endl;
}
}while(gn);
}
void jiechenhe(void)
{
float x;
float s;
x=0;
s=0.0;
cout<<"please input n to compute:1!+2!+...+n!"<<"\t";
cout<<"n=";
cin>>x;
cout<<"\n";
for(float i=1.0;i<=x;i++)
{
s=s+jiechen(i);
}
switch(int(x))
{
case 1:
{
cout<<"1!="<<s<<endl;
}
break;
case 2:
{
cout<<"1!+2!="<<s<<endl;
}
break;
case 3:
{
cout<<"1!+2!+3!="<<s<<endl;
}
break;
default:
{
cout<<"1!+2!+...+"<<x<<"!="<<s<<endl;
}
}
}
float jiechen(float n)
{
if(n==1) return 1;
else return jiechen(n-1)*n;
}
void jiecheng(void)
{
float x;
float s;
x=0;
s=0.0;
cout<<"please input x";
cin>>x;
s=jiechen(x);
cout<<"x!="<<s<<endl;
}
void sumjc(void)
{
}