Here the program for that (Tested). It will support to a max of 5x5 matric.
Before doing the multiplication you have to check i.e if your matric is of MxN and PxQ then if and only if N == P then you can perform the multiplication. And the resulted matric output will be of form MxQ.
And if you want to learn how the multiplication happen just go through this site (click on the below link).
Matrix Multiplication
#include <stdio.h>
void get_matrix_input(int (*matrix)[5], int row, int col)
{
int i, j;
printf("Enter the elemet of the matrxi(%d, %d)\n", row, col);
for (i = 0; i < row; i++)
for (j = 0; j < col; j++)
scanf("%d", &matrix[i][j]);
}
int main()
{
int row1, row2, col1, col2;
int mat_a[5][5], mat_b[5][5], res[5][5];
int i, j, k, sum = 0;
printf("Enter the number row and col for matric A : ");
scanf("%d%d", &row1, &col1);
get_matrix_input(mat_a, row1, col1);
printf("Enter the number row and col for matric B : ");
scanf("%d%d", &row2, &col2);
if (col1 != row2) {
printf("Matrices with entered orders can't be multiplied with each other.\n");
} else {
get_matrix_input(mat_b, row2, col2);
for (i = 0; i < row1; i++) {
for (j = 0; j < col2; j++) {
for (k = 0; k < row2; k++) {
sum += mat_a[i][k] * mat_b[k][j];
}
res[i][j] = sum;
sum = 0;
}
}
}
printf("Product of entered matrices :\n");
for (i = 0; i < row1; i++) {
for (j = 0; j < col2; j++)
printf("%d\t", res[i][j]);
printf("\n");
}
return 0;
}
Sample input and output:
Enter the number row and col for matric A : 2 3
Enter the elemet of the matrxi(2, 3)
1 2 3
4 5 6
Enter the number row and col for matric B : 3 2
Enter the elemet of the matrxi(3, 2)
7 8
9 10
11 12
Product of entered matrices :
58 64
139 154