#include "stdio.h"
main(){
int row1,col1,row2,col2,i,j,k,l,sum;
printf("Enter row and column of first matrix: ");
scanf("%d %d",&row1,&col1);
printf("Enter row and column of second matrix: ");
scanf("%d %d",&row2,&col2);
int matrix1[row1][col1],matrix2[row2][col2],mul[row1][col2];
if (col1==row2){
for (i=0;i<row1;i++){
for (j=0;j<col1;j++){
printf("Enter '%d' row '%d' column element of first matrix: ",i+1,j+1);
scanf("%d",&matrix1[i][j]);
}
}
for (i=0;i<row2;i++){
for (j=0;j<col2;j++){
printf("Enter '%d' row '%d' column element of second matrix: ",i+1,j+1);
scanf("%d",&matrix2[i][j]);
}
}
for (i=0;i<row1;i++){
for (j=0;j<col2;j++){
sum=0;
for(k=0;k<row2;k++){
sum+=matrix1[i][k]*matrix2[k][j];
}
mul[i][j]=sum;
}
}
for (i=0;i<row1;i++){
for (j=0;j<col2;j++)printf("%4d",mul[i][j]);printf("\n");
}
}
else printf("not possible\n");
}
main(){
int row1,col1,row2,col2,i,j,k,l,sum;
printf("Enter row and column of first matrix: ");
scanf("%d %d",&row1,&col1);
printf("Enter row and column of second matrix: ");
scanf("%d %d",&row2,&col2);
int matrix1[row1][col1],matrix2[row2][col2],mul[row1][col2];
if (col1==row2){
for (i=0;i<row1;i++){
for (j=0;j<col1;j++){
printf("Enter '%d' row '%d' column element of first matrix: ",i+1,j+1);
scanf("%d",&matrix1[i][j]);
}
}
for (i=0;i<row2;i++){
for (j=0;j<col2;j++){
printf("Enter '%d' row '%d' column element of second matrix: ",i+1,j+1);
scanf("%d",&matrix2[i][j]);
}
}
for (i=0;i<row1;i++){
for (j=0;j<col2;j++){
sum=0;
for(k=0;k<row2;k++){
sum+=matrix1[i][k]*matrix2[k][j];
}
mul[i][j]=sum;
}
}
for (i=0;i<row1;i++){
for (j=0;j<col2;j++)printf("%4d",mul[i][j]);printf("\n");
}
}
else printf("not possible\n");
}