#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;
}
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;
}