Question: Objective: To gain experience in writing recursive functions Write a menu-driven program with the following three options to call a recursive function to add the

Objective: To gain experience in writing recursive functions

Write a menu-driven program with the following three options

to call a recursive function to add the first n terms of the series 1/(0+1)+1/ (1+2)+1/(2+3)+1/(3+4)+...+1/((n-1)+n)- starting with 1

n=5: 1+1/(1+2)+1/(2+3)+1/(3+4)+1/(4+5)=1.787302

to call a recursive function, that produces the sum of the first n terms of the series (n*n)+((n-1) *(n-1)+...+(3*3)+(2*2)+(1*1) [ starting with n]

n=3: (3*3)+(2*2) +1 =14

to quit

Specifications/Requirements

no need to use classes

must have user-friendly interface/prompts/error messages (here and all other labs); user means a non-programmer

the user should be able to run the menu as many times as the user wants; print the menu every time

the recursive functions may not call any other functions

above zero numbers only

ask a user for the number of terms

use switch and enum to implement the menu (remember you can use int to read into enum variable, read into in int then cast it to enum)

if you find yourself trying to write a loop in a recursive function, you are on a wrong track; rethink your logic

in option 1, the first term to be printed as 1; for example, do not print (1*1*1), print 1

in option 2, print 2, do not print 2/1

terms to be printed recursively

the totals to be calculated recursively and printed inside the recursive functions

output formatting

option 1: for n=5 1+1/(1+2)+1/(2+3)+1/(3+4)+1/(4+5)=1.7873 where "1+1/(1+2)+1/(2+3)+1/(3+4)+1/(4+5)", "=", and 1.7873 to be produced and printed by the recursive function; 1/(0+1) to be printed as 1

option 2: for n=3 (3*3)+(2*2) +1 =14 where "(3*3)+(2*2) +1 =14", "=" and "14" to be produced and printed by the recursive function; (1*1) to be printed as 1

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!