How To Multiply Two Matrices?

Let the first matrix be A with size m × n

Let the second matrix be B with size n × p

Check that the number of columns in A equals the number of rows in B

Create a result matrix C with size m × p

For each row i in A

For each column j in B

Compute C[i][j] as the sum of A[i][k] × B[k][j] for k from 0 to n – 1

Place the computed value in C[i][j]

Repeat for all rows and columns

The resulting matrix C is the product of A and B

Suggested for You

Trending Today