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