/*
Name: WAP to Multiply two Matrix
Author: Parveen Malik
Date: 18/09/11 01:50
*/
#include<stdio.h>
#include<conio.h>
int main()
{
float a[10][10], b[10][10],c[10][10];
int m,n,p,q,i,j,k;
printf("Enter the size of Matrix A as m,n : ");
scanf("%d%d",&m,&n);
printf("Enter the size of Matrix B as p,q : ");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("\n Matrix Multipication AxB is not feasible\n");
exit(1);
}
printf("\n Enter the %d elements of Matrix A row-wise \n",m*n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("\n Enter the %d elements of Matrix B row-wise \n",p*q);
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%f",&b[i][j]);
}
}
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]+=a[i][k]*b[k][j];
}
}
}
printf("\n Product AxB is : \n\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%5.2f\t",c[i][j]);
}
printf("\n");
}
getch();
return 0;
}
OUTPUT :
0 comments:
Post a Comment