您的位置:首页 > 编程语言 > C语言/C++

C++primer plus第六版课后编程练习答案7.5

2015-11-27 16:43 423 查看
#include<iostream>
#include<cmath>
#include <string>   
using namespace std;

unsigned long jiecheng(unsigned n)
{
//	try
//	{
if(n>0)
return n*jiecheng(n-1);
else if(0==n)
return 1;
else
return 1;
//		else
//			throw -1;
//	}
//	catch(int e)
//	{
//        cout<<"negative number!"<<endl;
//		return 1;
//   }
}
void main()
{
unsigned n;
cout<<"请输入一个正整数参数:";
while(cin>>n)
{
cout<<n<<"的阶乘为"<<jiecheng(n)<<endl;
cout<<"请输入一个正整数参数:";
}

cin.clear();
cin.get();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: