Assume the following recursive function: (M-4) int sequence(int num) //Line 1 { //Line 2 if (num == 0) //Line 3 return num; //Line 4 else //Line 5 return(num + sequence num - 1)); //Line 6 } //Line 7 a. Identify the base case. b. Identify the general case. c. What valid values can be passed as parameters to the function sequence? d. If sequence (-3) is a valid call, what is its value? If not, explain why

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

1. Assume the following recursive function: (M-4)
int sequence(int num) //Line 1
{ //Line 2
if (num == 0) //Line 3
return num; //Line 4
else //Line 5
return(num + sequence num - 1)); //Line 6
} //Line 7
a. Identify the base case.
b. Identify the general case.
c. What valid values can be passed as parameters to the function sequence?
d. If sequence (-3) is a valid call, what is its value? If not, explain why.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning