Pseudo-code · Question 24 · Medium

What will be the output of the following pseudocode?

Integer x, y
Set x = 5, y = 0
do
    y = y + x
    x = x - 2
while (x > 0)
Print y
  1. 15
  2. 8
  3. 5
  4. 9
Answer and explanation

Answer: D. 9

Explanation: The body adds 5, then 3, then 1 to y, after which x becomes -1 and the loop stops. y = 5 + 3 + 1 = 9.

Previous: What will be the output of the following pseudocode? (Note: array indices… · Next: What will be the output of the following pseudocode? (Note: &, ^ and >> are…

Practise pseudo-code

Try a fresh set of pseudo-code questions with an explanation after every answer, free and without signing up: Pseudo-code practice. Or sit a full placement mock test.

More pseudo-code questions

More technical & programming practice

C Programming · Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge