ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer s = 0, i = 1
while (i <= 20)
    s = s + i
    i = i * 2 + 1
end while
Print s
  1. A. 11
  2. B. 26
  3. C. 57
  4. D. 15

Correct answer: B. 26

i goes 1, 3, 7, 15 (each is 2i + 1), and the next value 31 fails the test. s = 1 + 3 + 7 + 15 = 26.

More Pseudocode and Code Tracing questions

Exams that ask this topic