You are on page 1of 3

Matrix Multiplication

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,m,n,p,q;
char z;
float a[100][100],b[100][100],c[100][100];
cont:
printf("enter the order of matrix A :");
scanf("%d %d",&m,&n);
printf("enter the order of matrix B :");
scanf("%d %d",&p,&q);
if(n==p)
{
printf("\nmatrix multiplication is possible :\n");
printf("enter the values of matrix A: \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{

scanf("%f",&a[i][j]);
}
printf("\n");
}
printf("enter the values of matrix B: \n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%f",&b[i][j]);
}
printf("\n");
}
//matrix multiplication

printf("\n the muliplied matrix is C :\n");


for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;

for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
printf("%.2f\t",c[i][j]);
}
printf("\n");
}

}
else
printf("\n matrix multiplication is not possible : ");
printf("\ndo you wish to continue (y/n)? : ");
scanf("%s",&z);
if(z=='y'||z=='Y')
goto cont;
else
printf("\n*********program ends*********");
getch();
}

You might also like