Question: In C++, solve the problem using recursion. CANNOT USE FOR OR WHILE LOOPS. You are standing at the base of a staircase. At each step
In C++, solve the problem using recursion. CANNOT USE FOR OR WHILE LOOPS.
You are standing at the base of a staircase. At each step as you climb the staircase, you have the option of taking a small stride (one stair) or a large stride (two stairs - assuming there are at least two stairs remaining). Given that a staircase has X number of stairs, how many ways are there to climb the staircase using different combinations of small and large strides? Write a function that takes a total number of stairs in the staircase and returns the number of ways to climb it. If the staircase has three steps, for example, there are three ways to climb it (three small strides, or a large stride followed by a small stride, or a small stride followed by a large stride). Your function should look like this:
int waysToClimb(int numStairs) {
// ...
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
