Pseudo-code · Question 5 · Easy

What will be the output of the following pseudocode? (Note: / denotes integer division.)

Integer n, c
Set n = 1234, c = 0
while (n > 0)
    c = c + 1
    n = n / 10
end while
Print c
  1. 10
  2. 3
  3. 4
  4. 1234
Answer and explanation

Answer: C. 4

Explanation: Each iteration removes the last digit: 1234 → 123 → 12 → 1 → 0. The loop runs 4 times, so it counts the digits.

Previous: What will be the output of the following pseudocode? (Note: &, | and ^ are… · 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