Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Algorithms | Recursion | Question 2

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Consider the following recursive function fun(x, y). What is the value of fun(4, 3)




int fun(int x, int y) 
{
  if (x == 0)
    return y;
  return fun(x - 1,  x + y);

(A) 13
(B) 12
(C) 9
(D) 10


Answer: (A)

Explanation: The function fun() calculates and returns ((1 + 2 … + x-1 + x) +y) which is x(x+1)/2 + y.

Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads