multiplication of matrix
Wed Jan 24 2024 01:09:16 GMT+0000 (Coordinated Universal Time)
Saved by
@pvignesh
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],r1,c1,r2,c2,r3,c3,i,j,k;
printf("enter no.of row and colums of matrix a\n");
scanf("%d%d",&r1,&c1);
printf("enter no.of row and colums of matrix b\n");
scanf("%d%d",&r2,&c2);
if(r1==c2&&c1==r2)
{
printf("enter elements of 1st matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter elements of 2nd matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
r3=r1;
c3=c2;
for(i=0;i<r3;i++)
{
for(j=0;j<c3;j++)
{
c[i][j]=0;
for (k=0;k<r3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<r3;i++)
{
for(j=0;j<c3;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
}
}
content_copyCOPY
Comments