ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 48, b = 18, t
while (b != 0)
    t = b
    b = a mod b
    a = t
end while
Print a
  1. A. 6
  2. B. 144
  3. C. 0
  4. D. 18

Correct answer: A. 6

This is Euclid's algorithm: (48, 18) → (18, 12) → (12, 6) → (6, 0). The loop stops when b becomes 0 and prints the GCD, 6.

More Pseudocode and Code Tracing questions

Exams that ask this topic