Monday 25 April 2016

C++ Programming How to find Factorial using Functions

This Program will show how to find a factorial of any number using Function


Program # 5 : Factorial using Function :




#include <iostream>

using namespace std;

int factFinder(int x){
   if(x==0){
    return 1;
   }else{
     return x*factFinder(x-1);
   }

}


int main()
{
  cout << factFinder(5) << endl;
}


Note : You can use any integer number in the  code. I just use 5 .


Output of the Program :




0 comments:

Post a Comment