Friday, August 27, 2010

C Program to multiply two matrices


#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3];
int i,j,k;
clrscr();
printf(" Enter the 1st Matrix ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j] );
}
}
printf("\n Array A is \n");
for(i=0;i<3;i++)
{  printf("\n");
for(j=0;j<3;j++)
{
printf(" %d",a[i][j] );
}
}

printf(" Enter the 2nd Matrix ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j] );
}
}
printf("\n Array B is \n");
for(i=0;i<3;i++)
{  printf("\n");
for(j=0;j<3;j++)
{
printf(" %d",b[i][j] );
}
}

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
printf("\n Multiplied resultant array C is \n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
{
printf(" %d",c[i][j]);
}
}
getch();
}


No comments:

Post a Comment