ProgrammingModerateTCS NQT · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer lcm = 18, steps = 0
Integer a = 12, b = 18
while (lcm mod a != 0 OR lcm mod b != 0)
    lcm = lcm + 18
    steps = steps + 1
end while
Print lcm, steps
  1. A. 216 11
  2. B. 36 2
  3. C. 72 3
  4. D. 36 1

Correct answer: D. 36 1

The loop tries multiples of 18 until one is also divisible by 12: 18 fails, 36 works. One step is taken: 36 1.

More Pseudocode and Code Tracing questions

Exams that ask this topic