Matrix multiplication code
I can see the question clearly from your images. It’s about matrix multiplication
implementation in C.
The question is:
Consider the following code for multiplication of two matrices C = A × B.
MatMul(int *A, int *B, int *C, int nRowsA, int nColsA, int nRowsB, int
nColsB)
Inside, they’ve given:
int i, j, k;
for(i=0; i<nRowsA; i++)
for(j=0; j<nColsB; j++)
{
....
}
Now, we must fill the inner loop.
Correct inner code for matrix multiplication:
The formula is:
nColsA−1
C[i][j] = ∑
A[i][k] × B[k][j]
k=0
So, the correct code is:
1/2
C[i][j] = 0;
for(k=0; k<nColsA; k++)
C[i][j] += A[i][k] * B[k][j];
✅ Answer:
The correct option among the given choices is the one that first initializes C[i][j] =
0; and then uses:
for(k=0; k<nColsA; k++)
C[i][j] += A[i][k] * B[k][j];
Would you like me to also explain why the other options are wrong (like if they miss
initialization or swap indices)?
2/2