Input
Output
#include <stdio.h> #include <conio.h> void main() { int m, n, p, q, i, j, k, sum = 0; int first[5][5], second[5][5], multiply[10][10]; clrscr(); printf("Enter the no of rows and columns for first matrix: "); scanf("%d %d", &m, &n); printf("Enter the elements for first matrix\n"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &first[i][j]); } } printf("Enter the no of rows and columns for second matrix\n"); scanf("%d %d", &p, &q); printf("Enter the elements for second matrix\n"); for (i = 0; i < p; i++) { for (j = 0; j < q; j++) { scanf("%d", &second[i][j]); } } if (n != p) { printf("Matrices can't be multiplied with each other.\n"); } 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; } } printf("Product of the Matrices:\n"); for (i = 0; i < m; i++) { for (j = 0; j < q; j++) { printf("%d\t", multiply[i][j]); } printf("\n"); } } getch(); }