您的位置:首页 > 其它

复习内容

2016-06-15 17:59 363 查看
#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;

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