CJCoding With Joseph
← Back to Question List
C++ Code Walkthrough #34

Fibonacci Recursion

hardRecursion

📄 Code

Read carefully — what does this print?
1#include <iostream>
2using namespace std;
3int fib(int n) {
4 if (n < 2) return n;
5 return fib(n - 1) + fib(n - 2);
6}
7int main() {
8 cout << fib(7) << endl;
9 return 0;
10}

🎯 Your Answer