ProgrammingHardTCS NQT · Infosys
What will be the output of the following pseudocode? (All variables are integers, so / is integer division; and / are evaluated left to right)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division; * and / are evaluated left to right)
Integer p = 1000, years = 0
while (p < 2000)
p = p + p * 7 / 100
years = years + 1
end while
Print years, p- A. 10 1967
- B. 10 2000
- C. 11 2098
- D. 12 2245
Correct answer: C. 11 2098
Each year adds 7% rounded down: 1070, 1144, 1224, 1309, 1400, 1498, 1602, 1714, 1833, 1961, 2098. The amount first reaches 2000 after 11 years: 11 2098 (the rule of 72 suggests about 10).
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? Integer h[6] = {2, 1, 5, 6, 2, 3}, best = 0 for (each i from 0 to 5) Integer mn =…
- What will be the output of the following pseudocode? String stream = "aabcbc" Integer cnt[26] = all 0 Queue q = empty for (each ch in…
- What will be the output of the following pseudocode? Procedure f(Integer n) if (n == 0) return end if Print n f(n - 1) Print n End…
- What will be the output of the following pseudocode? // a trie (prefix tree) starts with only an empty root for each word in {"car"…
- What will be the output of the following pseudocode? // LRU cache of capacity 2: get(k) returns the value or -1; put evicts the least…
- What will be the output of the following pseudocode? Integer g[3][4] = {{1, 1, 1, 0}, {1, 1, 1, 1}, {0, 1, 1, 1}} Integer c = 0 for (each…