Pseudo-code · Question 20 · Easy
What will be the output of the following pseudocode? (Note: / denotes integer division.)
Integer n, rev
Set n = 507, rev = 0
while (n > 0)
rev = rev * 10 + (n mod 10)
n = n / 10
end while
Print rev
- 507
- 75
- 705
- 57
Answer and explanation
Answer: C. 705
Explanation: The loop takes the last digit each time: rev becomes 7, then 70, then 705. The middle 0 is kept because it is not a leading zero of the result.
Previous: What will be the output of the following pseudocode? · Next: What will be the output of the following pseudocode? (Note: for-loop bounds…
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?
- 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?
- 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…
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