Factorial

#include<iostream>
using namespace std;
int main()
{
int n,i,f=1;
  cin>>n;
    try
     {
    if(n>0&&n<20)
     {
        for(i=1;i<n+1;i++)
        f=f*i;
        cout<<"Factorial of a given Number is= "<<f;
  }
     else if(n<0)
     throw (0);
     if(n>20)
    throw(1.0);
     }
catch(int i)
    {
      cout<<"Factorial of a given Number is= "<<i;
    }
  return 0;
}

No comments:

Post a Comment