Matrix multiplication in c language: c program to multiply matrices (two dimensional array), this program multiplies two matrices which will be entered by the user. Firstly user will enter the order of a matrix. If the entered orders of two matrix is such that they can't be multiplied then an error message is displayed on the screen. You have already studied the logic to multiply them in Mathematics. Matrices are frequently used while doing programming and are used to represent graph data structure, in solving system of linear equations and many more
Algorithm: Multiplication of two matrix
Rule: Multiplication of two matrix is only possible if first matrix has size m X n and other matrix has size n x r. Where m, n and r are any positive integer.
Multiplication of two matrices is defined as
Where 1 ≤ i ≤ m and 1 ≤ j ≤ n
For example: Suppose two matrix A and B of size of 2 x 2 and 2 x 3 respectively
![C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuH8CJBNYaISJUdzD2Hk6oZmut07-wM5a8yK4flmx54df69hYi9Cb5ucw8I81S8u1WqgySuGd86PqCY7m4Bt6_r-xnan-IQNgyx8SSCI6rpxVhPowKnZC_3nLVO54IisQ115N-FypApYc/s320/muli2.png)
Algorithm: Multiplication of two matrix
Rule: Multiplication of two matrix is only possible if first matrix has size m X n and other matrix has size n x r. Where m, n and r are any positive integer.
Multiplication of two matrices is defined as
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi2P3RAXy-xPdR7ZKLzygI-b9XVCT3sFmRqPD0n9-zNd6fQHOfjtM94QRDlYRGMLLajGCz2QWdYU47F4vsMZxjeFCnhdO6FaDSXyvMG1nEqZiP5LXpDF8Nh9QKmogL6SheDg4ATRLRKCs/s200/muli.png)
For example: Suppose two matrix A and B of size of 2 x 2 and 2 x 3 respectively
![C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuH8CJBNYaISJUdzD2Hk6oZmut07-wM5a8yK4flmx54df69hYi9Cb5ucw8I81S8u1WqgySuGd86PqCY7m4Bt6_r-xnan-IQNgyx8SSCI6rpxVhPowKnZC_3nLVO54IisQ115N-FypApYc/s320/muli2.png)
Example: C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays
Output
Enter rows and columns for first matrix: 2
2
Enter rows and columns for second matrix: 2
3
Enter elements of matrix 1
Enter element A11 : 1
Enter element A12 : 2
Enter element A21 : 3
Enter element A22 : 4
Enter elements of matrix 2
Enter element B11 : 5
Enter element B12 : 6
Enter element B13 : 7
Enter element B21 : 8
Enter element B22 : 9
Enter element B23 : 10
Product of entered matrices:-
21 24 27
47 54 61
إرسال تعليق
Thank you for vising