A C program to find product of two matrix
#include<stdio.h>
#include<conio.h>
void main()
{
int m1[100][100],m2[100][100],pro[100][100],r1,c1,r2,c2,i,j,k;
clrscr();
printf("\nEnter the order of matrix1 OR How many Row and Colum\n");
scanf("%d%d",&r1,&c1);
printf("\nEnter the order of matrix2 OR How many Row and Colum\n");
scanf("%d%d",&r2,&c2);
if(c1!=r2)
{
printf("\nMultipliction is not POSSIBLE\n");
}
else
{
printf("\nEnter the elements of first Matrix\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&m1[i][j]);
}
}
printf("\nEnter the elements of second Matrix\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&m2[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
pro[i][j]=0;
for(k=0;k<r2;k++)
pro[i][j]=pro[i][j]+(m1[i][k]*m2[k][j]);
}
}
printf("The product is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ",pro[i][j]);
}
printf("\n");
}
}
getch();
}
|