Question: Write a C++ program that recursively computes each term of G(n) up to and including a given n . You can hard code the input

Write a C++ program that recursively computes each term of G(n) up to and including a given n . You can "hard code" the input value (the program does not need to accept any input) but you will need to set it sufficiently high so you can determine your answer for the second part below -- you may need to experiment with different values.

The formula is:

G(n) = 1 + G(n - G(G(n - 1)))

Remember to think about the base case.

Example Output

The output of your program does not need to exactly match this, but please make sure each term is output on a separate line along with the n for that term.

For n = 15:

1: 1 2: 2 3: 2 4: 3 5: 3 6: 4 7: 4 8: 4 9: 5 10: 5 11: 5 12: 6 13: 6 14: 6 15: 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To write a C program that computes the recursive sequence Gn 1 Gn GGn 1 lets tackle the problem step ... View full answer

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 Programming Questions!