ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
Integer s = 0
for (each i from 1 to 10)
    s = s + (i * i) / 3
end for
Print s
  1. A. 385
  2. B. 126
  3. C. 127
  4. D. 128

Correct answer: B. 126

Each term is cut down separately: 0, 1, 3, 5, 8, 12, 16, 21, 27, 33, which adds up to 126. Dividing the total at the end (385 / 3 = 128) gives the trap.

More Pseudocode and Code Tracing questions

Exams that ask this topic