Josif_tepe

Untitled

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