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
- 15
- 8
- 5
- 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
- What will be the output of the following pseudocode? (Note: for-loop bounds…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: array indices…
- What will be the output of the following pseudocode? (Note: &, ^ and >> are…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: array indices…
- What will be the output of the following pseudocode?
- What will be the output of the following pseudocode? (Note: for-loop bounds…
- What will be the output of the following pseudocode? (Note: for-loop bounds…
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