ProgrammingHardAccenture · Capgemini

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer r[3][4] = {{1, 2, 3, 4}, {2, 4, 6, 8}, {4, 2, 5, 1}}
Integer c = 0
for (each j from 0 to 3)
    Integer v = r[0][j]
    Boolean inAll = true
    for (each i from 1 to 2)
        if (v does not occur in row i) inAll = false
    end for
    if (inAll) c = c + 1
end for
Print c
  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 4

Correct answer: B. 2

Only values of row 0 that also appear in rows 1 and 2 count: 1 is missing from row 1 and 3 from both, while 2 and 4 are in every row. c = 2.

More Pseudocode and Code Tracing questions

Exams that ask this topic