MATRIX MULTIPLICATION - C-Tutorial

Latest

Monday, 26 September 2016

MATRIX MULTIPLICATION

/* MATRIX MULTIPLICATION*/


#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k,r1,c1,r2,c2,a[10][10],b[10][10],c[10][10];
clrscr();
printf("\n Enter the 'A' matrix row and column size :");
scanf("%d%d",&r1,&c1);
printf("\n Enter the 'B' matrix row and column size :");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("\n Enter the 'A' matrix elements :");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n Enter the 'B' matrix elements :");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
printf("\n The result of matrix multiplication is:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%3d",c[i][j]);
}
printf("\n");
}
}
else
{
printf("\n The matrix multiplication is not possible ");
}
getch();
}

No comments:

Post a Comment