#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a[2][2],b[2][2],c[2][2];
int r1,c1,r2, c2,i,j,k ,s;
printf("Enter the row and column of 1st matrix\n");
scanf("%d%d",&r1,&c1);
printf("Enter the row and column of 2nd matrix\n");
scanf("%d%d",&r2,&c2);
if(c1!=r2)
{
printf("\n Matrices are not multiplicable");
exit(0);
}
printf("\n Enter the element of first matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n enter the element of second matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("The first matrix is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("The second matrix is\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
s=0;
for(k=0;k<c1;k++)
{
s=s+a[i][k]*b[k][j];
c[i][j]=s;
}
}
}
printf("Multiplication of two matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
getch();
}
Output:
Enter the row and column of 1st matrix
2 2
Enter the row and column of 2nd matrix
2 2
Enter the element of first matrix
1 2 3 4
enter the element of second matrix
1 2 3 4
The first matrix is
1 2
3 4
The second matrix is
1 2
3 4
Multiplication of two matrix
7 10
15 22
Program:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer