Question: Problem 4a: Write a recursive C++ program to solve the following problem : P(1) = 3 P(2) = 4 P(n) =P(n-1)+P(n-2) for n>2 To test

Problem 4a: Write a recursive C++ program to solve the following problem :

P(1) = 3

P(2) = 4

P(n) =P(n-1)+P(n-2) for n>2

To test output for P(4)=11 P(6) = 29 and P(7) =47

Hint: main shall call a function int par(int n) that returns 3 if n=1, it returns 4 if n = 2, and it returns par(n-1) + par(n-2) if n>2.

Sample Output (Your name will replace mine & yours will be P(5))

John shows P( 7) has 47 units

b: Draw a call tree for P(5). This should look similar to Figure 2.30 in the textbook. Note: the numbers just above the ovals are the return values. You may hand draw and scan, but you can complete in Google Suites or an App of your choice.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!