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
  1. A. 11
  2. B. 24
  3. C. 26
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic