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.
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
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning