The following code is supposed to return n!, for positive n.  int factorial(int n){   if (n == 0)     return 1;   else     return (n + factorial(n - 1)); } An analysis of the code using our "Three Question" approach reveals that:  Group of answer choices it fails the base-case question. it fails the smaller-caller question. it fails the general-case question. it passes on all three questions and is a valid algorithm. None of these is correct.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 28SA
icon
Related questions
Question

30The following code is supposed to return n!, for positive n. 


int factorial(int n){
  if (n == 0)
    return 1;
  else
    return (n + factorial(n - 1));
}

An analysis of the code using our "Three Question" approach reveals that: 

Group of answer choices

it fails the base-case question.

it fails the smaller-caller question.

it fails the general-case question.

it passes on all three questions and is a valid algorithm.

None of these is correct.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
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