Write a program in C++ to find the Factorial by recursive function.

7/07/2014 01:22:00 pm Unknown 0 Comments

Write a program to find the Factorial by recursive function. This function will use recursion to find factorial of a given number. You can also calculate factorial a number with non recursive method for. Click Here to get code of non recursive method to find factorial of a given number. 



#include<iostream.h>

using namespace std;

int recurs_funct(int num){
    static int i=1;// to make one number initialize
    cout<<i<<" : numbers"<<endl; // count the function calls

    if(num==1){
      return 1;//base
       }
   else{
        i++;
        return  num=num*recurs_funct(num-1);
        }
}

int main(){

    cout<<"Enter to number to find Factorial: ";
    int number;
    cin>>number;
    number=recurs_funct(number); // function call
    cout<<"\t\t\tFactorial of number is: "<<number;
    cout<<"\n\n\n\n";
    system("pause");



}