Program
#include<stdio.h>
main()
{
int a[100][100],b[100][100],c[100][100],n,m,i,j,o,p,k,l;
printf("enter the order of matrix 1\n");
scanf("%d%d",&n,&m);
printf("enter the order of matrix 2\n");
scanf("%d%d",&o,&p);
if(m!=o)
{
printf("matrix multiplication not possible\n");
}
else
{
printf("enter matrix 1 values\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter matrix 2 values\n");
for(k=0;k<o;k++)
{
for(l=0;l<p;l++)
{
scanf("%d",&b[k][l]);
}
}
for(i=0;i<n;i++)
{
for(l=0;l<p;l++)
{
c[i][l]=0;
}
}
for(i=0;i<n;i++)
{
for(l=0;l<p;l++)
{
for(j=0;j<m;j++)
{
c[i][l]=c[i][l]+(a[i][j]*b[j][l]);
}
}
}
printf("the resultant matrix is \n");
for(i=0;i<n;i++)
{
for(l=0;l<p;l++)
{
printf("%d\t",c[i][l]);
}
printf("\n");
}
}
}
output:
No comments:
Post a Comment