Input
Output
#include <iostream> using namespace std; int main() { int m = 2, n = 2, p = 2, q =2, i, j, k, sum = 0; int first[5][5]= { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25} }, second[5][5] = { {3, 2, 3, 3, 5}, {6, 1, 8, 9, 10}, {11, 12, 5, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25} }, multiply[10][10]; cout << "Enter the no of rows and columns for first matrix: "; cout << m << " " << n << endl; cout << "Enter the elements for first matrix: "; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cout << first[i][j] << " "; } } cout << "\nEnter the no of rows and columns for second matrix: "; cout << p << " "<< q << endl; cout << "Enter the elements for second matrix: "; for (i = 0; i < p; i++) { for (j = 0; j < q; j++) { cout << second[i][j] << " "; } } if (n != p) { cout << "\nMatrices can't be multiplied with each other."; } else { for (i = 0; i < m; i++) { for (j = 0; j < q; j++) { for (k = 0; k < n; k++) { sum = sum + first[i][k]*second[k][j]; } multiply[i][j] = sum; sum = 0; } } cout << "\nProduct of the Matrices:" << endl; for (i = 0; i < m; i++) { for (j = 0; j < q; j++) { cout << multiply[i][j] << " "; } cout << endl; } } return 0; }