/* *copyright (c) 2014, Yantai University School of computer
*all rights reserved.
* File name: Annpion.cpp
* Author: Wang Yaopeng
* Completion date: June 20, 2015
* version number: v1.0
*
* Problem Description: n! function, when the user's input is negative, And when the number of inputs is too large (for example, greater than 12), use the exception handling mechanism to reject them and give appropriate hints. .
* Input Description: Enter an integer.
* Output Description: output factorial result.
*/
#include <iostream>
using namespace std;
int FAC (int i)
{
int s=1;
if (i<0| | I>12)
throw i;
while (i)
{
s*=i;
-----I.
}
return s;
}
int main ()
{
int A;
Try
{
cout<< "Please enter a number to be asked for factorial:";
cin>>a;
cout<<a<< "! =" <<fac (a) <<endl;
}
catch (int a)
{
if (a<0)
cout<<a<< "< 0, cannot find factorial. "<<endl;
else
{
cout<<a<< "> 12, the number is too large. "<<endl;}}
Operation Result: