ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, r[3][3];
for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) r[j][2 - i] = m[i][j];
printf("%d %d %d", r[0][0], r[0][2], r[2][0]);
  1. A. 3 9 1
  2. B. 1 7 3
  3. C. 7 9 1
  4. D. 7 1 9

Correct answer: D. 7 1 9

Row i of m becomes column 2 − i of r, which rotates the matrix 90° clockwise: r is 7 4 1 / 8 5 2 / 9 6 3. So r[0][0] = 7, r[0][2] = 1 and r[2][0] = 9. '3 9 1' is the anticlockwise rotation.

More C Programming questions

Exams that ask this topic