ProgrammingModerateAccenture · Capgemini

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer m[4][4], s = 0
for (each i from 0 to 3)
    for (each j from 0 to 3)
        m[i][j] = 4 * i + j + 1
    end for
end for
for (each i from 0 to 3)
    for (each j from 0 to 3)
        if (i == 0 OR j == 0 OR i == 3 OR j == 3)
            s = s + m[i][j]
        end if
    end for
end for
Print s
  1. A. 102
  2. B. 136
  3. C. 34
  4. D. 120

Correct answer: A. 102

m holds 1 to 16 row by row. The border leaves out only the inner 6, 7, 10, 11 (sum 34), so the border sum is 136 − 34 = 102.

More Pseudocode and Code Tracing questions

Exams that ask this topic