Advertisement
pasholnahuy

fact recurse

May 4th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int fact(int n) {
  7.     if (n == 1) {
  8.         return 1;
  9.     }
  10.     return n * fact(n - 1);
  11. }
  12.  
  13. int main()
  14. {
  15.     int n;
  16.     cin >> n;
  17.  
  18.     cout  <<  fact(n) <<  endl;
  19.  
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement