ProgrammingHardInfosys SP · TCS Digital

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 144, b = 89, t, steps = 0
while (b != 0)
    t = a mod b
    a = b
    b = t
    steps = steps + 1
end while
Print steps, a
  1. A. 11 1
  2. B. 9 1
  3. C. 10 89
  4. D. 10 1

Correct answer: D. 10 1

144 and 89 are consecutive Fibonacci numbers, the worst case for Euclid: the remainders walk down 55, 34, 21, 13, 8, 5, 3, 2, 1, 0, which is 10 steps, ending with gcd 1. Output 10 1.

More Pseudocode and Code Tracing questions

Exams that ask this topic