复习内容

来源:互联网 发布:nginx last 编辑:程序博客网 时间:2024/05/17 23:04
#include <iostream>
using namespace std;
int fac(int n)
{
    int result=1;
    if(n<0)
        throw string("Argument cannot be negative");
    else if(n>12)
        throw n;
    while(n)
    {
        result*=n;
        n--;
    }
    return result;
}


int main( )
{
    int n;
    try
    {
            cout<<"Please input a number n to xalculte n!:";
            cin>>n;
            cout<<n<<"!="<<fac(n)<<endl;
    }
    catch(int)
    {
        cout<<"Exception occurred: Too large!"<<endl;
    }
    catch(string s)
    {
        cout<<"Exception occurred: "<<s<<endl;
    }
    return 0;
}
0 0
原创粉丝点击