Example 71: Product of Matrices

Learn how to calculate the product of two matrices.

Problem

Write a program to obtain the product of two 3 x 3 matrices.

The function takes in three 2-D arrays as parameters, where the first two arrays represent the original matrices, and in the third array, you need to store the multiplication result.

Note: For matrix multiplication, the number of columns of the first matrix and the number of rows of the second matrix should be equal; otherwise, the matrices cannot be multiplied.

Example

Input (Matrix 1, Matrix 2) Output (Matrix 3)
1 1 1
1 1 1
1 1 1

2 2 2
2 2 2
2 2 2
6 6 6
6 6 6
6 6 6

Demonstration

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.