ProgrammingVery hardProduct company OA
What will be the output of the following pseudocode? (/ is integer division.)
What will be the output of the following pseudocode? (/ is integer division.)
Integer c = 0
for (n = 1 to 200)
Integer s = 0, t = n
while (t > 0)
s = s + t mod 10
t = t / 10
end while
if (s == 10)
c = c + 1
end if
end for
Print c- A. 18
- B. 10
- C. 20
- D. 19
Correct answer: D. 19
Two-digit numbers with digit sum 10: 19, 28, 37, 46, 55, 64, 73, 82, 91 → 9. In 100–199 the last two digits must sum to 9: 109, 118, 127, 136, 145, 154, 163, 172, 181, 190 → 10. 200 has digit sum 2. Total 19. Forgetting 190 (or 109) gives 18.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (isComposite[] starts all false; ops counts every assignment inside the inner loop…
- What will be the output of the following pseudocode? (&& stops as soon as the left side is false) Integer c = 0, k = 0 Function f(Integer…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Procedure show(Integer n) if…
- What will be the output of the following pseudocode? (| is bitwise OR) Integer x = 0, c = 0 while (x < 1000) x = x | (x + 1) c = c + 1 end…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer arr[7] = {1, 2, 3, 4, 5, 6, 7} reverse(arr, 0, 2)…
- What will be the output of the following pseudocode? (the static s keeps its value between calls; in f(n - 1) + s the call is evaluated…