Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please HELPPP: data Structure / use for c++ Suppose a stair way has N steps wher

ID: 3845999 • Letter: P

Question

please HELPPP: data Structure / use for c++

Suppose a stair way has N steps where N is a positive integer. How many different ways can you up the stair way if, as you up, sometimes you go up one stair step with one step or you go up two stair step with one step.

Suppose the stair way has 3 steps then you can up the stair way

three different ways:

1,1,1 = 3 steps

1,2 = 3 steps

2, 1 = 3 steps

Suppose the stair way has 4 steps then you can up the stair way

five different ways

1,1,1,1 = 4 steps

1,1,2 = 4 steps

1,2,1 = 4 steps

2, 1,1, = 4 steps

2,2 = 4 steps

Write a recursive function to solve the problem.

The function, f, will contain statements that will look like,

...

return f(N-1) + f(N-2)

Write a program to test the function with many, different values of N.

Explanation / Answer

#include<iostream>

using namespace std;

int f(int N)

{

if( N<=1)

return N;

return f(N-1) + f(N-2);

}

int main()

{

int N = 4;

int res = f(N+1);

cout << res << endl;

return 0;

}