ProgrammingModerateTCS NQT · Wipro

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer m[3][3] = {{11, 2, 4}, {4, 5, 6}, {10, 8, -12}}
Integer d1 = 0, d2 = 0
for (each i from 0 to 2)
    d1 = d1 + m[i][i]
    d2 = d2 + m[i][2 - i]
end for
Print d1, d2, abs(d1 - d2)
  1. A. 4 19 15
  2. B. 4 19 23
  3. C. 19 4 15
  4. D. 4 18 14

Correct answer: A. 4 19 15

Main diagonal: 11 + 5 − 12 = 4. Other diagonal: 4 + 5 + 10 = 19. Absolute difference 15: output 4 19 15.

More Pseudocode and Code Tracing questions

Exams that ask this topic