ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer s = 0
for (i = 1 to 30)
if (i mod 4 == 0)
continue
end if
if (i mod 7 == 0)
break
end if
s = s + i
end for
Print s- A. 17
- B. 21
- C. 24
- D. 28
Correct answer: A. 17
i = 1, 2, 3 are added (6); i = 4 is skipped by continue; 5 and 6 are added (17); i = 7 triggers break before it is added. s = 17. '21' adds 4 (continue ignored); '24' adds 7 before breaking.
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? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)…
- What will be the output of the following pseudocode? (Strings are indexed from 0; swap exchanges two characters.) String s = "ABCDEF"…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1 to 5) for (j = i to 5) if ((i + j) mod 3 == 0) c = c + 1 end…
- What will be the output of the following pseudocode? (/ is integer division; calls counts every call of f.) Integer calls = 0 Function…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer a[5] = {1, 2, 3, 4, 5}, t for (i = 0 to 4) t =…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer a[5] = {5, 1, 8, 2, 3}, c = 0 for (i = 0 to 3)…