ProgrammingModerateTCS NQT · Wipro

Read the pseudocode. a = 1, b = 1, s = 0 for i = 1 to 6 t = a + b a = b b = t if (t mod 3 == 0) s = s + t else s = s - 1 end for print s What is printed?

  1. A. 24
  2. B. 21
  3. C. 20
  4. D. 19

Correct answer: C. 20

t takes 2, 3, 5, 8, 13, 21. Only 3 and 21 are multiples of 3, giving +24, while the other four values each subtract 1: 24 - 4 = 20.

More Pseudocode and Code Tracing questions

Exams that ask this topic