ProgrammingHardTCS NQT · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer i = 1, c = 0
while (i <= 100)
i = i * 2 + c
c = c + 1
end while
Print c, i- A. 6 118
- B. 7 120
- C. 6 121
- D. 6 57
Correct answer: C. 6 121
The new i uses the old c: 1 → 2 → 5 → 12 → 27 → 58 → 121, with c going up by one each pass. 121 is the first value over 100, after 6 passes: 6 121.
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? // list: 1 -> 2 -> 3 -> 4 -> 5 -> NULL, head points to node 1 Node prev = NULL, cur =…
- What will be the output of the following pseudocode? (a loop whose start is greater than its end runs zero times) Integer count = 0…
- What will be the output of the following pseudocode? Integer stars = 0 Procedure p(Integer n) stars = stars + 1 for (each i from 1 to n)…
- What will be the output of the following pseudocode? (& is bitwise AND on two's-complement integers) Integer n = 360 while (n > 0) Print n…
- What will be the output of the following pseudocode? (substring(s, i, k) is the k characters starting at index i; indices start at 0)…
- What will be the output of the following pseudocode? Function F(Integer n) if (n == 0) return 1 end if return n - M(F(n - 1)) End Function…