//CODE
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],s[10][10];
int sum=0,i,j,k,r1,c1,r2,c2;
printf("\n Enter the rows of 1st matrix:");
scanf("\n %d",&r1);
printf("\n Enter the columns of 1st matrix:");
scanf("\n %d",&c1);
printf("\n Enter the rows of 2nd matrix:");
scanf("\n %d",&r2);
printf("\n Enter the columns of 2nd matrix:");
scanf("\n %d",&c2);
if(r2==c1)
{
printf("\n Enter the matrix a:\n ");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n Enter the matrix b:\n ");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n The matrix a is as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(" \t %d",a[i][j]);
}
printf("\n");
}
printf("\n The matrix b is as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(" \t %d",b[i][j]);
}
printf("\n");
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
sum=0;
for(k=0;k<c2;k++)
{
sum=sum+(a[i][k]*b[k][j]);
}
s[i][j]=sum;
}
}
printf("The resultant matrix is: \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("\t %d",s[i][j]);
}
printf("\n");
}
}
else
{
printf("\n Matrix cannot be multiplied...Try again");
}
getch();
return 0;
}
//OUTPUT
Enter the rows of 1st matrix:2
Enter the columns of 1st matrix:3
Enter the rows of 2nd matrix:3
Enter the columns of 2nd matrix:2
Enter the matrix a:
2
1
3
5
6
4
Enter the matrix b:
9
8
7
3
2
5
The matrix a is as follows:
2 1 3
5 6 4
The matrix b is as follows:
9 8
7 3
2 5
The resultant matrix is:
25 19
87 58