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- A. 100
- B. 125
- C. 450
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Count the pairs (i, j) with 1 <= i <= j <= 10 for which the product i j is a perfect square. The procedure below does this with two nested…
- The procedure below finds the largest prime less than 100 by testing each candidate from 99 down to 2 for divisibility by 2 up to its…
- The procedure below sums the integers from 1 to 100 that are NOT divisible by 2 and NOT divisible by 3. What is printed? total = 0 for n =…
- Count the numbers n with 1 <= n <= 100 such that both n and n + 2 are prime (twin primes, lower member n). The procedure below checks…
- The procedure below counts the odd divisors of 1000 by testing every d from 1 to 1000. What is printed? count = 0 for d = 1 to 1000 if…
- Fibonacci numbers are defined by F0 = 0, F1 = 1 and Fn = Fn-1 + Fn-2. The procedure below computes F50 by iteration and then prints F50…