Question:

Consider the following ANSI C program.

 

The output of the program upon execution is \(\underline{\hspace{2cm}}\).

Show Hint

Recursive functions with two decreasing parameters often form combinatorial recursion trees.
Updated On: Dec 30, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 60

Solution and Explanation

Step 1: Understand base conditions.
The function returns \( q \) when both \( x \le 0 \) and \( y \le 0 \).

Step 2: Recursive behavior.
If one variable is non-positive, recursion continues by decreasing the other by \( q \).
If both are positive, the function branches into two recursive calls.

Step 3: Evaluate \( \text{foo}(15,15,10) \).
\[ \text{foo}(15,15,10) = \text{foo}(15,5,10) + \text{foo}(5,15,10) \] Each of these further expands until base cases are reached. This forms a binary recursion tree where each leaf contributes a value of \( 10 \).

Step 4: Count base case occurrences.
The recursion generates exactly 6 base case hits.

Step 5: Compute final result.
\[ \text{Result} = 6 \times 10 = 60 \] % Final Answer

Final Answer: \[ \boxed{60} \]

Was this answer helpful?
0
0

Questions Asked in GATE CS exam

View More Questions