Advertisement
Josif_tepe

Untitled

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