Question:

Consider the following C code segment:

int x = 126, y = 105;
do {
    if (x > y)
        x = x - y;
    else
        y = y - x;
} while (x != y);

printf("%d", x);

The output of the given C code segment is ____________. (Answer in integer)

Show Hint

The given C code implements the Euclidean algorithm to compute the greatest common divisor (GCD) of two numbers.
Updated On: Jan 30, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 21

Solution and Explanation

This code implements the Euclidean algorithm to compute the greatest common divisor (GCD) of \( x = 126 \) and \( y = 105 \). The loop continuously subtracts the smaller number from the larger until both are equal. The final value is the GCD, which is 21.
Was this answer helpful?
0
0