ProgrammingHardTCS NQT · Infosys · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer s = 0
for (each i from 1 to 10)
if (i mod 3 == 0) continue
if (i > 8) break
s = s + i
end for
Print s- A. 19
- B. 28
- C. 37
- D. 27
Correct answer: D. 27
Added: 1, 2, 4, 5, 7, 8 = 27. Multiples of 3 are skipped, and the loop stops at i = 10 (i = 9 is skipped by continue).
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 r r = (12 AND 10) OR (5 XOR 3) Print r
- What will be the output of the following pseudocode? Integer x = 3 x = x << 2 x = x + (x >> 1) Print x
- What will be the output of the following pseudocode? String s = "PROGRAM", t = "" for (each i from 0 to length(s) - 1) if (i mod 2 == 1) t…
- What will be the output of the following pseudocode? Integer i = 1, c = 0 while (i <= 20) i = i 2 c = c + 1 end while Print i, c
- What will be the output of the following pseudocode? Integer n = 6, c = 0 while (n != 1) if (n mod 2 == 0) n = n / 2 else n = 3 n + 1 end…
- What will be the output of the following pseudocode? Integer n = 37 String out = "" while (n > 0) out = out + (n mod 2) n = n / 2 end…