Question:

Consider the following ANSI C function: 

int SomeFunction(int x, int y) 
{
if ((x == 1) || (y == 1)) return 1; 
if (x == y) return x; 
if (x > y) return SomeFunction(x - y, y); 
if (y > x) return SomeFunction(x, y - x); 
} 

The value returned by SomeFunction(15, 255) is \(\underline{\hspace{2cm}}\).

Show Hint

Repeated subtraction in recursion is a form of the Euclidean algorithm for GCD.
Updated On: Dec 30, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 15

Solution and Explanation

The function repeatedly subtracts the smaller number from the larger. This is equivalent to the Euclidean algorithm for computing: \[ \gcd(x, y) \] \[ \gcd(15, 255) = 15 \] Thus, the function returns: \[ 15 \] Final Answer: \[ \boxed{15} \]
Was this answer helpful?
0
0

Questions Asked in GATE CS exam

View More Questions