Question: Write a recursive function to sum a series of numbers from 1.....n based on an option. If the option is 1, the function returns the

Write a recursive function to sum a series of numbers from 1.....n based on an option. If the option is 1, the function returns the sum of all odd numbers from 0....n and if the option is 2, the function returns the sum of all even numbers from 0....n. Example: sumRecursive(int n, int option) sumRecursive(5, 1) : returns 1+3+5 sumRecursive(5, 2) : returns 2+4 Input: Two numbers, n is the end point of the series and option is the desired option Output: The sum of the series based on an option. Constraints: n>0 Sample Input 1: 5 1 Sample Output 1: 9 Sample Input 2: 5 2 Sample Output 2: 6

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!