Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int fibbonaci(int n) {
- if(n <= 2) {
- return 1;
- }
- return fibbonaci(n - 1) + fibbonaci(n - 2);
- }
- int main() {
- cout << fibbonaci(4) << endl;
- return 0;
- }
- // fibonaci(4) = fibonaci(3) + fibonaci(2) = 2 + 1 = 3
- //fibonaci(2) = 1
- //fibonaci(3) = fibonaci(2) + fibonaci(1) = 1 + 1 = 2
- //fibonaci(2) = 1
- // fibonaci(1) = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement