2015 big, 15th week. Item 2-The factorial of some numbers no, forget it.

Source: Internet
Author: User
/* *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:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.