ProgrammingModerateTCS NQT · Wipro
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 s = 0
for (each i from 1 to 10)
s = s + 100 / i
end for
Print s- A. 291
- B. 293
- C. 292
- D. 281
Correct answer: A. 291
Integer division drops each fraction: 100 + 50 + 33 + 25 + 20 + 16 + 14 + 12 + 11 + 10 = 291. Rounding each quotient instead gives 293, truncating the exact sum 292.9 once gives 292, and stopping at i = 9 gives 281.
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) Integer n = 360, d = 2, s = 0…
- What will be the output of the following pseudocode? Integer count = 0, s for (each n from 2 to 500) s = 1 for (each d from 2 to n - 1) if…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer count = 0, n, s, d for…
- What will be the output of the following pseudocode? Integer c = 0 for (each y from 1890 to 2010) if ((y mod 4 == 0 AND y mod 100 != 0) OR…
- What will be the output of the following pseudocode? (AND has higher precedence than OR) Integer a = 5, b = 2, c = 3 if (a > b OR b > c…
- What will be the output of the following pseudocode? Integer calls = 0 Function f(Integer m, Integer n) calls = calls + 1 if (m == 0 OR n…