C program to multiply two matrices and create Single Result Matrix
Simple C program to do multiplication of given matrices
Code:
#include<conio.h>#include<stdio.h>
void main()
{
clrscr();
int a[3][3],b[3][3],c[3][3],i,j,k;
printf("Enter the matrix values of A:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("Enter the element number A%d%d:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Enter the matrix values of B:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("Enter the element number B%d%d:",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{ c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k] *b[k][j];
}
}
}
Printf(“Result matrix: “);
for(i=0;i<3;i++)
{ printf("\n");
for(j=0;j<3;j++)
{
printf("%d",c[i][j]);
}
}
getch();
}
Comments
Post a Comment