#include <iostream>
using namespace std;
int f(int i) {
if(i == 1) {
return (1);
}
else {
return 2*f(i-1);
}
}
int main() {
cout << f(5) << endl; //<--- I don't understand why this is 16.
return 0;
}
I am having trouble understanding why f(5) = 16 when I run the program.
i = 5 // 2(4) = 8
i = 4 // 2(3) = 6
i = 3 // 2(2) = 4
i = 2 // 1
these don't add to 16. I would really appreciate some guidance.