n!

来源:互联网 发布:新域名后缀 编辑:程序博客网 时间:2024/04/27 22:27
#include<iostream>
using namespace std;
double fun(int x)
{
if(x<0)
return 0.0;
else if(x==0)
return 1;
else
return x*fun(x-1);
}
int main()
{
int n;
for(;;)
{
cout<<"Please input the positive integer:"<<endl;
cin>>n;
if(n<0)
break;
else 
cout<<"The result is:"<<fun(n)<<endl;
}//end for(;;)
cout<<"Thank you for using!"<<endl;


}
0 0
原创粉丝点击