Advertisement
Josif_tepe

Untitled

Feb 18th, 2025
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <cmath>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int rec(int x) {
  8.     if(x < 2) {
  9.         return 1;
  10.     }
  11.     return x * rec(x - 1);
  12. }
  13. int main()
  14. {
  15.    
  16.     cout << rec(5) << endl;
  17.  
  18.     return 0;
  19. }
  20. // rec(5) = 5 * rec(4) = 5 * 24 = 120
  21. // rec(4) = 4 * rec(3) = 4 * 6 = 24
  22. // rec(3) = 3 * rec(2) = 3 * 2 = 6
  23. // rec(2) = 2 * rec(1) = 2 * 1 = 2
  24. // rec(1) = 1
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement