What is the output of the statement


Discuss the below:

Q1: 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.

Q2. Consider the following recursive function:

void funcRec(int u, char v)
{
if(u == 0)
cout<else if(u == 1)
cout<(static_cast(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');

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: What is the output of the statement
Reference No:- TGS01937731

Now Priced at $25 (50% Discount)

Recommended (99%)

Rated (4.3/5)