Identify the base case.

Assignment Help C/C++ Programming
Reference no: EM13938229

1. 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.

2. 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');

Reference no: EM13938229

Questions Cloud

Prepare the entry by green bay to record the delivery : Prepare the entry by Green Bay to record the delivery of 150 units during 2011. Wausau pays in cash upon delivery for units not covered by the deposit.
Prepare an additional detail claim : Prepare an additional detail claim in order to adjust the cost overrun. For example, under the part "d" instead of timber trusses client prefers steel trusses. It causes massive impact on rates whereas the provided BoQ doesn't have such items. In ..
Which medications would you anticipate holding : Prior to Mrs. Tell's 10am surgery, which medications will you administer and which medications would you anticipate holding? Please give the rationale for your answer.
Compute the warranty expense : Compute the warranty expense for 2009. What is the December 31, 2009, balance in the estimated warranty liability account? Prepare the entry to record the payment of the 2009 warranty claims.
Identify the base case. : What valid values can be passed as parameters to the function mystery?
Identify the factors affecting executive compensation : Identify the different stakeholder(s) to consider. Identify the factors affecting executive compensation. Describe the impact of unionization on wages
Ways information systems can improve our lives : What are some of the ways information systems can improve our lives?  What are some of the bene?ts organisations seek to achieve through using information systems?
What are the physiological challenges an organism : What are the physiological challenges an organism (such as a waterbug) might experience in a freshwater lake of the following conditions: depth of 200 m, water cold (approx 10 degrees celcius on surface), eutrophic, poor visibility, pH approx. 4?
What is the incremental profit associated with adding : What is the incremental profit associated with adding a round trip flight?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Implement a point class for two-dimensional points

Implement a Point class for two-dimensional points (x, y). Include a default constructor, a copy constructor, a negate() function to transform the point into its negative, a norm() function to return the point's distance from the origin (0,0), an..

  Write a parallel program with the sequent simulator

Complete the following program to write a parallel program with the Sequent Simulator for the following task: Hire two processors. One processor searches the first half of a array and finds the largest number. The second processor searches the sec..

  Computes the sum and displays it

Prepare a C++ program that asks the user for an integer n and computes the sum 1^2+2^2+3^2+4^2+....+n^2 and displays it in the output screen.

  A perfect solution is impossible or too expensive

Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical p..

  Make the program as efficient as possible

Write a Forms application, using loops, that generates the following diamond pattern when the button is clicked. For your output, use a multi-line textbox with the TextAlign property set to Center. Make the program as efficient as possible! You ca..

  Determine the reynolds number of flow in a rectangular

determine the reynolds number of flow in a rectangular channel 2m deep and 4m wide if the water level is 60 and running

  Write table_avg function to find the average of an array.

Write table_print function to print out a table of size. Print output on one line.table_print(array, size);

  Write a function named read_line

supposes you have a directory whose name is stored in 'specs.file_dir' which contains a file whose name is stored in 'specs.file_name'.

  Program that asks user to enter the size of the matrix

Write a program that asks user to enter the size of the matrix (rows and column) then, it asks the user to enter the elements of two matrices and finally it adds two matrix and displays the result in C language.

  An essential component of compromised to a resource

1. true or false? an essential component of compromised to a resource is that the situation resulting in the compromise was motivated by malice. A.true B.false

  Write a function that collects integers from the user

Write a function that collects integers from the user until a 0 is encountered and returns them in a list in the order they were input (ML only).

  What does the given code print

What does the following code print: char* s1 = "ABCDE"; char* s2 = "ABCE"; if (strcmp(s1,s2) endl; else cout = " endl.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd