C Program for matrix multiplication
- Jino Shaji
- Dec 30, 2014
- 1 min read
Updated: Jun 9, 2020
#include
#include
main()
{
int m1[20][20],i,j,k,m2[20][20],mult[20][20],r1,r2,c1,c2;
clrscr();
printf(“Enter the order of the first matrix in the format of row,colum\n”);
scanf(“%d%d”,&r1,&c1);
printf(“ENTER THE ELEMENTS OF THE FIRST MATRIX in row wise\n”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf(“%d”,&m1[i][j]);
}
}
printf(“Enter the order of the second matrix in the format of row,colum\n”);
scanf(“%d%d”,&r2,&c2);
printf(“ENTER THE ELEMENTS OF THE SECOND MATRIX in row wise\n”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf(“%d”,&m2[i][j]);
}
}
if(r2==c1)
{
for(i=0;i<r1;i++) // Multiplication Of Matrix
{
for(j=0;j<c1;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
}
}
}
printf(“FIRST MATRIX\n”);
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(“%d\t”,m1[i][j]);
}
printf(“\n”);
}
printf(“SECOND MATRIX\n”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“%d\t”,m2[i][j]);
}
printf(“\n”);
}
printf(“PRODUCT OF MATRIX\n”);
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf(“%d\t”,mult[i][j]);
}
printf(“\n”);
}
} // ……….if END
else
{
printf(“MATRIX MULTIPLICATION IS NOT POSSOBLE\n”);
}
getch();
return(0);
}
Output

Comments