ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 1, b = 1, c
for (each i from 1 to 6)
    c = a + b
    a = b
    b = c
end for
Print b
  1. A. 21
  2. B. 8
  3. C. 13
  4. D. 34

Correct answer: A. 21

b runs through the Fibonacci numbers 2, 3, 5, 8, 13, 21 over the six passes. Stopping one pass short gives the trap 13.

More Pseudocode and Code Tracing questions

Exams that ask this topic