/*
*Copyright (c) 2014,烟台大学计算机学院
*All rights reserved.
*文件名称:main.cpp
*作者:苏强
*完成日期:2015年6月21日
*版本号:v1.0
*
*问题描述:编写一个程序,求输入数的平方根。设置异常处理,当输入负数时采用异常处理机制给出提示。
*/
#include<iostream>
#include<cmath>
using namespace std;
int F(int n)
{
int a=1;
if(n<1)
throw string(" ");
else if(n>12)
throw n;
else
{
while(n)
{
a*=n;
n--;
}
}
return a;
}
int main()
{
double m;
try
{
cout<<"请输入一个将要进行阶乘的数:"<<endl;
while(cin>>m)
cout<<m<<" 的阶乘为 "<<F(m)<<endl;
}
catch(int)
{
cout<<"输入的数太大!"<<endl<<endl;
}
catch(string)
{
cout<<"输入的数为负数,无法计算!"<<endl;
}
return 0;
}