ProgrammingVery hardTCS NQT · Infosys

What is the trace of the matrix product A B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program.

What is the trace of the matrix product A * B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program.
#include <stdio.h>
int main(void) {
    int A[2][2] = {{1, 2}, {3, 4}}, B[2][2] = {{5, 6}, {7, 8}}, 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", C[0][0] + C[1][1]);
}
  1. A. 70
  2. B. 68
  3. C. 69
  4. D. 72

Correct answer: C. 69

C[0][0] = 1*5 + 2*7 = 19 and C[1][1] = 3*6 + 4*8 = 50, so the trace is 69.

More C Programming questions

Exams that ask this topic