Assume X and Y are non-zero positive integers. Consider the following pseudo-code fragment:
Assume X and Y are non-zero positive integers. Consider the following pseudo-code fragment:
while X<>Y do
if X>Y then
X ← X−Y
else
Y ← Y−X
endif
end while
print (X)
What is the code doing?
Show answerHide answer
Correct answer: (A) It computes the GCD of two numbers.
Explanation
This is the subtraction form of Euclid's algorithm: repeatedly subtracting the smaller number from the larger one until both are equal leaves their GCD.