The following recursive function takes three positive integer arguments:  def compute(n,x,y) :     if n==0 : return x     return compute(n-1,x+y,y)   What is the value returned by the compute function? n*x+y x+y x+n*y x What if: will the returned value be for the compute function defined in the question above if the argument n is negative? x x-n*y x+n*y The function will never return a value.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

The following recursive function takes three positive integer arguments:

  1.  def compute(n,x,y) :
  2.     if n==0 : return x
  3.     return compute(n-1,x+y,y)
 
What is the value returned by the compute function?
  1. n*x+y
  2. x+y
  3. x+n*y
  4. x

What if: will the returned value be for the compute function defined in the question above if the argument n is negative?

  1. x
  2. x-n*y
  3. x+n*y
  4. The function will never return a value.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
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
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