How to answer the following questions Given the following code, what are the constraints on the input argument? int mystery(int num){ if (num == 0) return 0; else if (num > 100) return -1; else return num + mystery(num – 1); } A. It must be between 0 and 100 inclusive. B. It must be greater than 0. C. It must be less than 0 or greater than 100. D. It must be greater than or equal to 0.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

How to answer the following questions

Given the following code, what are the constraints on the input argument?

int mystery(int num){

  if (num == 0) return 0;

  else

  if (num > 100) return -1;

  else

    return num + mystery(num – 1);

}

A. It must be between 0 and 100 inclusive.  B. It must be greater than 0.
C. It must be less than 0 or greater than 100.
D. It must be greater than or equal to 0.
 

The number of recursive calls that a method goes through before returning is called:  A. order of growth efficiency.  B. the depth of recursion.

C. combinatorial recursive count.

D. activation stack frame.
 

The following code is supposed to return the sum of the numbers between 1 and n inclusive, for positive n. An analysis of the code using the "Three Question" approach reveals that:

int sum(int n){

  if (n == 1)

    return 1;

  else

    return (n + sum(n));

}

A. it fails the base-case question.  B. it fails the smaller-caller question.
C. it fails the general-case question.
D. it passes on all three questions and is a valid algorithm.
 
 
 
 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
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