ProgrammingHardTCS NQT · Infosys
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer total = 0, n
for (each i from 1 to 100)
n = i
while (n > 0)
total = total + n mod 10
n = n / 10
end while
end for
Print total- A. 5050
- B. 900
- C. 901
- D. 1000
Correct answer: C. 901
For 1 to 99, each digit 0–9 appears 10 times in the units place and 10 times in the tens place: 2 × 10 × 45 = 900. Adding 100 (digit sum 1) gives 901.
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? (All variables are integers, so / is integer division; + joins strings) Function…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {2, 5, 9}, {4, 6, 0}} Integer bad = 0 for (each i from…
- What will be the output of the following pseudocode? (operands are evaluated strictly left to right) Integer a = 7, b = 3 a = a + b - (b =…
- What will be the output of the following pseudocode? Integer calls = 0 Function C(Integer n, Integer k) calls = calls + 1 if (k == 0 OR k…
- What will be the output of the following pseudocode? // Integer16: 16-bit signed integers in two's complement; results wrap around…
- What will be the output of the following pseudocode? Record r[4] = {(3, 'a'), (1, 'b'), (3, 'c'), (1, 'd')} // (key, letter) for (each i…