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

Recursion with a Step of Two

mediumRecursion

📄 Code

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

🎯 Your Answer