HOME

Sunday, November 29, 2015

FACTORIAL USING RECURSION

#include<iostream>
using namespace std;
int fact(int);
int main()
{
    int num;
    cout<<"ENTER NUMBER"<<endl;
    cin>>num;
    cout<<"Factorial is "<<fact(num)<<endl;
    return 0;
}
int fact(int num)
{
    if(num==1 || num==0)
    {
        return 1;
    }
    else
    {
        return num*fact(num-1);
    }
}

No comments:

Post a Comment