Advertisement
SabirSazzad

Factorial Using Recurssion

Feb 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int factorial(int num)
  4. {
  5.     int result = 1;
  6.     if(num != 1)
  7.     {
  8.         result = num*factorial(num-1);
  9.     }
  10.         return result;
  11. }
  12.  
  13. int main ()
  14. {
  15.     int num;
  16.     cout << "Input Value for Factorial: ";
  17.     cin >> num;
  18.     if(num == 0)
  19.     {
  20.         cout << "Factorial Value is: 1";
  21.     }
  22.     else
  23.     {
  24.         cout << "Factorial Value is: " << factorial(num) <<endl;
  25.     }
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement