Advertisement
Raqeeb_Alnakib

Factorial in C++

Nov 1st, 2019
6,858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. /*
  2.  
  3. Please, Don't Miss Visit My Site:
  4.  
  5.  
  6. https://global-prog.com
  7.  
  8.  
  9. */
  10.  
  11.  
  12.  
  13.  
  14.  
  15. #include<iostream>
  16. using namespace std;
  17.  
  18. int factorial(int x) {
  19.     if (x == 0) {return 1;}
  20.     else { return (x * factorial(x - 1)); }
  21. }
  22.     int main()
  23.     {
  24.         int x;
  25.         cout << "Enter the number to take the factorial : ";
  26.         cin >> x;
  27.         cout << x << "! = " << factorial(x) << endl;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement