ProgrammingHardAccenture · Capgemini
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0
for (each i from 1 to 6)
for (each j from 1 to 6)
if ((i * j) mod 4 == 0)
break
end if
c = c + 1
end for
end for
Print c- A. 11
- B. 24
- C. 26
- D. 15
Correct answer: A. 11
break leaves only the inner loop. Counts per i: i = 1 → 3 (stops at j = 4), i = 2 → 1 (stops at j = 2), i = 3 → 3, i = 4 → 0, i = 5 → 3, i = 6 → 1. Total 11.
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? (Strings are indexed from 0; + joins strings) String s = "AAABCCDAA", r = "" Integer…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function f(Integer n) if (n ==…
- What will be the output of the following pseudocode? (ref means the argument is passed by reference; other parameters are copies)…
- What will be the output of the following pseudocode? (/ is integer division) Stack st = empty for each token t in "6 2 3 + - 3 8 2 / + "…
- What will be the output of the following pseudocode? Integer a = 144, b = 89, t, steps = 0 while (b != 0) t = a mod b a = b b = t steps =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; , / and mod have equal…