#include<stdio.h>
int main()
{
int i,j,k,n,m,p,q,sum=0;
printf("Enter the order of 1st matrix m*n \n ");
scanf("%d%d",&m,&n);
printf("Enter the order of 2nd matrix p*q \n ");
scanf("%d%d",&p,&q);
int a[m][n],b[p][q],c[m][q];
if(n==p)
{
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf("Enter the 1st matrix [%d][%d]",i,j);
scanf("%d",&a[i][j]);
}
}
for (i=0;i<p;i++)
{
for (j=0;j<q;j++)
{
printf("Enter the 2nd matrix [%d][%d]",i,j);
scanf("%d",&b[i][j]);
}
}
for (i=0;i<m;i++)
{
for (j=0;j<q;j++)
{
for(k=0;k<m;k++)
{
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
} sum=0;
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
else
printf("Not Valid Matrix");
return 0;
}
int main()
{
int i,j,k,n,m,p,q,sum=0;
printf("Enter the order of 1st matrix m*n \n ");
scanf("%d%d",&m,&n);
printf("Enter the order of 2nd matrix p*q \n ");
scanf("%d%d",&p,&q);
int a[m][n],b[p][q],c[m][q];
if(n==p)
{
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf("Enter the 1st matrix [%d][%d]",i,j);
scanf("%d",&a[i][j]);
}
}
for (i=0;i<p;i++)
{
for (j=0;j<q;j++)
{
printf("Enter the 2nd matrix [%d][%d]",i,j);
scanf("%d",&b[i][j]);
}
}
for (i=0;i<m;i++)
{
for (j=0;j<q;j++)
{
for(k=0;k<m;k++)
{
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
} sum=0;
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
else
printf("Not Valid Matrix");
return 0;
}
0 Comments