ProgrammingModerateTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

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

Correct answer: B. 8

a takes the values 1, 1, 2, 3, 5, 8 across the six passes (b leads by one term, ending at 13).

More Pseudocode and Code Tracing questions

Exams that ask this topic