ProgrammingEasyTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer s = 0
for (each i from 1 to 10)
    if (i mod 2 == 0)
        s = s + i
    end if
end for
Print s
  1. A. 20
  2. B. 30
  3. C. 55
  4. D. 25

Correct answer: B. 30

The loop adds only the even values 2 + 4 + 6 + 8 + 10 = 30. Adding the odd values instead gives the trap 25.

More Pseudocode and Code Tracing questions

Exams that ask this topic