定义一个求n!的函数,n的缺省值为10

来源:百度知道 编辑:UC知道 时间:2024/06/23 09:23:52
这是我编的,帮我看看哪里有问题,我输不出来。
很急,知道的人帮帮忙啊!!!!!
#include<iostream>
using namespace std;
void delay(float n=10)
{for (;n>0;n--);}
void main()
{
float a;
cout<<"救命"<<a<<'\n';
delay();
}
要用缺省参数值的方法编。

楼上说的严重了,不过你的程序真的没法看。。。我尽力改改吧。

#include<iostream>
using namespace std;

int delay(float n=10)
{
int nj=1;
for (;n>0;n--)
nj*=n;
return nj;
}

void main()
{
cout<<"n!="<<delay()<<'\n';

}

你编的这段基本上跟这个问题没什么关系……

#include<iostream>
using namespace std;
int Factorial(int n=10)
{
int Res=1;
for (;n>0;n--) Res*=n;
return Res;
}
void main()
{
int a;
cout<<"Input a number:"<<endl;
cin>>a;
cout<<a<<"!="<<Factorial(a)<<endl;
}

#include<iostream>
using namespace std;

long factorial(int n);
int main()
{
int n;
cout<<"请输入整数n:";
cin>>n;
cout<<n<<" 的阶乘为:"<<factorial(n)<<endl;
return 0;