Matrices play a vital role in many diverse fields, including computer graphics, cryptography, and wireless communication.

One of the operations you might need to perform on them is matrix multiplication.

But exactly how do you multiply matrices?

Mathmatical illustrations on Blackboard

Import the stdio library to input numbers and display the output accordingly.

Check that matrix multiplication is possible.

If all is good, define two multidimensional arrays,m1andm2, with the size that the user provided.

Matrix multiplication illustration

Ask the user to enter the elements of both matrices one by one.

Use a nestedforloop to take the input for both the row and column of the matrix.

Define a third matrix,mul, of order r1 * c2 to store the result.

Matrix multiplication result illustration

Use a nestedforloop to perform the multiplication.

Remember to initialize the result to zero before adding to it.

Display the multiplied matrix using a nested for loop that iterates over the resultant matrices' rows and columns.

Output of Matrix Multiplication

Use the new-line character (\n) to display each of the rows on a separate line.

Return 0 to exit the main function and the program.

You’ll mainly use matrices in mathematics to solve linear equations and represent transformations such as rotation or translation.

Output of Matrix Multiplication when not possible