ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer v = 1
for (k = 0 to 4)
    v = v * 2 + k
end for
Print v
  1. A. 58
  2. B. 32
  3. C. 57
  4. D. 42

Correct answer: A. 58

v: 1 → 2 → 5 → 12 → 27 → 58 (k = 0..4). Ignoring the + k gives 2⁵ = 32. Each step doubles the accumulated value, so earlier k contribute more.

More Pseudocode and Code Tracing questions

Exams that ask this topic