#include<stdio.h>
#include<conio.h>
int m1[20][20],m2[20][20],ans[20][20];
void product(int x1,int y1,int x2,int y2)
{
int i,j,k;
for(i=0;i<x1;i++)
for(j=0;j<y2;j++)
for(k=0;(k<y1)||(k<x2);k++)
ans[i][j]+=m1[i][k]*m2[k][j];
}
void main()
{
int r1,c1,r2,c2,i,j;
clrscr();
printf("\nEnter the order of Matrix 1\t: ");
scanf("%d%d",&r1,&c1);
printf("\nEnter the elements of matrix 1:\n");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
printf("\nEnter the order of Matrix 2\t: ");
scanf("%d%d",&r2,&c2);
printf("\nEnter the elements of matrix 2:\n");
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
if(r1==c2)
{
printf("\nThe product is:\n\n\t");
product(r1,c1,r2,c2);
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf(" %d",ans[i][j]);
printf("\n\t");
}
}
else
printf("\n Matrix Multiplication not possible");
getch();
}