ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

Count the three-digit numbers (100 to 999) in which every digit is odd. The procedure below uses a loop over the numbers and checks each digit. What is printed?

Count the three-digit numbers (100 to 999) in which every digit is odd. The procedure below uses a loop over the numbers and checks each digit. What is printed?
count = 0
for n = 100 to 999
    if every digit of n is odd then count = count + 1
end for
Print count
  1. A. 100
  2. B. 125
  3. C. 450
  4. D. 500

Correct answer: B. 125

The first digit has 5 odd choices (1, 3, 5, 7, 9), and so do the second and third, giving 5 x 5 x 5 = 125. Requiring every digit even gives 100, checking only the last digit gives 450, and checking only the first digit gives 500.

More Pseudocode and Code Tracing questions

Exams that ask this topic