ProgrammingEasyTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer A[6] = {5, 1, 7, 3, 9, 2}, s = 0
for (each i from 0 to 5, step 2)
    s = s + A[i]
end for
Print s
  1. A. 6
  2. B. 27
  3. C. 21
  4. D. 15

Correct answer: C. 21

Indexes 0, 2, 4 hold 5, 7, 9 whose sum is 21. 6 is the sum of the odd-index elements.

More Pseudocode and Code Tracing questions

Exams that ask this topic