Ask Question
29 September, 19:44

Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle (3, 7) < end) return start - end; else if (start = = end) return start + end; else return end * puzzle (start + 1, end - 1); }

A. 10

B. 21

C. 42

D. 420

+1
Answers (1)
  1. 29 September, 22:58
    0
    Option D is the correct answer for the above question snip.

    Explanation:

    Here Puzzle is a recursive function which takes two argument start and end which execute like this.

    Firstly execution starts from main function and values 3 and 7 pass as an argument for the variable start and end. Then In the Puzzle function, else block is execute because the value of the "start" variable is not greater or equal to the value of the "end" variable. Then again Puzzle function is called with the value of 4 and 6 for the start and end variable. One's time again puzzle function is called for the value of 5 and 5 for the start and end variable.

    It means that puzzle function is called at three times--

    First time from main. And two times from puzzle function and return the value of 7*6 (42). Then the start and end value are the same and return the value of start+end which is 5+5 (10). Then the total value returned is 10*42 which is 420. Then the output will be 420.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Consider the accompanying definition of a recursive function. What is the output of the following statement? cout ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers