/*calculates the product of two matrices*/
#include <stdio.h>
#define MAX 8
int main()
{
int a[MAX][MAX], b[MAX][MAX];
int c[MAX][MAX] = { 0 };
int ra, ca, rb, cb;
int i, j, k;
printf ("Rows of the first matrice : "); scanf("%d", &ra);
printf ("Columns of the first matrice : "); scanf("%d", &ca);
printf ("Rows of the second matrice : "); scanf("%d", &rb);
printf ("Columns of the second matrice : "); scanf("%d", &cb);
if ( ca != rb) {
printf ("Matrices are not proper for multiplication\n");
return 0; }
printf ("First matrice: \n");
for (i = 0; i < ra; i++) {
for (j = 0; j < ca; j++) {
printf (" [%d,%d]: ",i+1,j+1);
scanf ("%d", &a[i][j]);
}
}
printf ("Second matrice: \n");
for (j = 0; j < rb; j++) {
for (k = 0; k < cb; k++) {
printf (" [%d,%d]: ",j+1,k+1);
scanf ("%d", &b[j][k]);
}
}
for (i = 0; i < ra; i++) {
for (j = 0; j < cb; j++) {
for (k = 0; k < ca; k++)
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
printf ("Product:\n");
for (i = 0; i < ra; i++) {
for (k = 0; k < cb; k++)
printf ("\t%d",c[i][k]);
printf ("\n");
}
return 0;
}