Loading...

Factorial_Recursion.cpp


/*/////////////////////////////////////////////////////////////////////////////
 * Factorial using recurrsion
 * Shubham Kumar
 * sshubhamk1@hotmail.com
/////////////////////////////////////////////////////////////////////////////*/

#include <iostream>
using namespace std;

long fact(int num);
int main(void)
{
    int num;
    do
    {
        cout <<"Enter the number: ";
        cin >> num;
        if(num <0)
        {
            cout << "Number should be non-negative. Try agian..."<<endl;
        }
    }while(num <0);
    cout << "The Factorial of "<< num << " is "<< fact(num) << endl;
    return 0;
}
long fact(int num)
{
    if(num <2)
        return 1;
    else
        return num *fact(num - 1);}


123 Sample Rd, Samplington, SA 12345
(555) 0123