0

i want a full code for finding different ways to climb the n-stair case problem that is each step is either 1 or 2 stairs.
Eg- a 3-stairs staircase can be climbed in 3 ways :1-1,1-2,2-1.

Using subset method can any one can help me out for this problem?

3
Contributors
2
Replies
19
Views
3 Years
Discussion Span
Last Post by iamthwee
0

c++ but you get the idea:

#include <iostream>
#include <string>

using namespace std;

string steps_taken = "";

void steps(int n, string steps_taken) {
    if (n == 0) {
        cout << steps_taken << endl;
    }
    if (n >= 1) {
        steps(n - 1, steps_taken + "1");
    }
    if (n >= 2) {
        steps(n - 2, steps_taken + "2");
    }
}


int main()
{
    int number = 4;

    steps(number,"");


}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.