Question 64

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?
  1. AIt computes the GCD of two numbers.
  2. BIt computes the LCM of two numbers.
  3. CIt finds the smallest of two numbers.
  4. DIt divides the largest number by the smaller.
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.

From DSSSB TGT Computer Science Practice Set 2

This is question 64 of DSSSB TGT Computer Science Practice Set 2. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.