ProgrammingHardProduct company OA

What is printed?

What is printed?
int A[2][2] = {{1, 2}, {3, 4}}, B[2][2] = {{0, 1}, {1, 0}}, C[2][2] = {0};
for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
        for (int k = 0; k < 2; k++) C[i][j] += A[i][k] * B[k][j];
printf("%d %d %d %d", C[0][0], C[0][1], C[1][0], C[1][1]);
  1. A. 2 1 4 3
  2. B. 1 2 3 4
  3. C. 3 4 1 2
  4. D. 2 4 1 3

Correct answer: A. 2 1 4 3

Multiplying A on the right by the swap matrix B swaps A's columns: [[2, 1], [4, 3]]. B × A would swap rows instead ('3 4 1 2'), which is the usual mix-up of order.

More C Programming questions

Exams that ask this topic