I am trying to self learn C++, and I bought a tutorial book. Right now, I am on a section about recursives. I got the first example, one to output the Fibonacci sequence, but I am stumped on the second one. The exercises do not come with answers, and that is why I am asking.
I have a ladder with 6 rungs. I can climb up 1 rung, 2 rungs, or 3 rungs at a time. The goal is to find every way I can climb up 10 rungs. For example, the program should output the paths I could take. {1 2 3 4 5 6} , {3.6}. {2 3 4 6}. etc.
I have absolutely no idea how to approach it other than I should probably use an array. If someone could give me part of the code, an outline of the code, or something to point me in the right direction, that'd be great. Don't just want the entire code because that would defeat the purpose.
It is much tougher than the fibonacci code I wrote.
#include <iostream.h>
int print(int i) {
if (i < 1) {
return 0;}
else if (i == 1 || i == 2) {
return 1;
} else {
return print(i-1) + print(i-2);
}
}
int main() {
int n = 10;
for (int i = 1; i <= n; i++) {
cout << fib(i) << " ";
}
cout << endl;
}