ProgrammingEasyAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer s = 0
for (i = 10; i >= 1; i = i - 3)
    s = s + i
end for
Print s
  1. A. 22
  2. B. 21
  3. C. 18
  4. D. 55

Correct answer: A. 22

i takes the values 10, 7, 4 and 1 (the next value, -2, fails i >= 1). Sum = 22.

More Pseudocode and Code Tracing questions

Exams that ask this topic