Answer:
see explaination
Explanation:
#include <stdio.h>
#include <malloc.h>
void matrix_mult(int **m1, int **m2, int **m3, int n, int m) {
int i, j, k, sum=0;
for(i = 0; i < n; ++i) {
for(j = 0; j < n; ++j) {
sum = 0;
for(k = 0; k < m; ++k) {
sum += m1[i][k] * m2[k][j];
}
m3[i][j] = sum;
}
}
}
int main() {
int n, m, i, j;
int **m1, **m2, **m3;
printf("Enter number of rows: ");
scanf("%d", &n);
printf("Enter number of columns: ");
scanf("%d", &m);
m1 = malloc(sizeof(int *) * n);
m2 = malloc(sizeof(int *) * m);
m3 = malloc(sizeof(int *) * n);
for(i = 0; i < m; ++i) {
m1[i] = malloc(sizeof(int) * m);
m2[i] = malloc(sizeof(int) * n);
m3[i] = malloc(sizeof(int) * n);
}
printf("Enter first matrix\n");
for(i = 0; i < n; ++i) {
for(j = 0; j < m; ++j) {
scanf("%d", &(m1[i][j]));
}
}
printf("Enter second matrix\n");
for(i = 0; i < m; ++i) {
for(j = 0; j < n; ++j) {
scanf("%d", &(m2[i][j]));
}
}
matrix_mult(m1, m2, m3, n, m);
printf("product is\n");
for(i = 0; i < n; ++i) {
for(j = 0; j < n; ++j) {
printf("%d ", m3[i][j]);
}
printf("\n");
}
printf("Enter first matrix: ");
return 0;
}