ProgrammingHardTCS NQT · Accenture pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer x = 1, i = 1
while (i <= 5)
    x = x + i * i
    i = i + 1
end while
Print x
  1. A. 55
  2. B. 56
  3. C. 50
  4. D. 30

Correct answer: B. 56

x starts at 1 and adds the squares 1,4,9,16,25 one by one: 1+1+4+9+16+25 = 56.

More Pseudocode and Code Tracing questions

Exams that ask this topic