Purchase Solution

An Example of Recursion Recursive Function in C++

Not what you're looking for?

Ask Custom Question

Consider the following recursive function.

int mystery(int number)
{
if(number == 0)
return number;
else
return(number + mystery(number - 1));
}

a. Identify the base case.
b. Identify the general case.
c. What valid values can be passed as parameters to the function mystery?
d. If mystery(0) is a valid call, what is its value? If not, explain why.
e. If mystery(5) is a valid call, what is its value? If not, explain why.
f. If mystery(-3) is a valid call, what is its value? If not, explain why.

8. Consider the following recursive function:

void funcRec(int u, char v)
{
if(u == 0)
cout<<v;
else if(u == 1)
cout<<static_cast<char>(static_cast<int>(v) + 1);
else
funcRec(u - 1, v);
}

a. Identify the base case.
b. Identify the general case.
c. What is the output of the following statement? funcRec(5, 'A');

Purchase this Solution

Solution Summary

For two different recursive functions, teaches how to identify the following:
a. Identify the base case.
b. Identify the general case.
c. What valid values can be passed as parameters to the function(s)?
d. Various test cases

Solution Preview

Consider the following recursive function.

int mystery(int number)
{
if(number == 0)
return number;
else
return(number + mystery(number - 1));
}

a. Identify the base case.
Base case is
if(number == 0)
return number;

b. Identify the general case.
return(number + mystery(number - 1);

c. What valid values ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Javscript Basics

Quiz on basics of javascript programming language.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.