ProgrammingModerateTCS NQT · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer s = 0, i = 0
while (i < 10)
i = i + 1
if (i mod 3 == 0)
continue
end if
s = s + i
end while
Print s- A. 37
- B. 55
- C. 18
- D. 27
Correct answer: A. 37
i is increased before the test, so continue cannot cause an endless loop. The sum takes 1 to 10 except 3, 6, 9: 55 − 18 = 37.
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? (Arrays are indexed from 0) Integer a[5] = {10, 20, 30, 40, 50}, b[5], k = 2, n = 5…
- What will be the output of the following pseudocode? (Strings are indexed from 0) String s = "ABBCCCDDDD" Integer best = 0, run = 1 for…
- What will be the output of the following pseudocode? Integer M[2][2] = {{1, 1}, {1, 0}}, R[2][2] = {{1, 0}, {0, 1}}, T[2][2] for (each k…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer s = 0 for (each i from…
- 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…