multiplication of Matrix in C, C assignment to multiplication of matix M x N in C, C assignment to solve multiplication of matrix.
#include
#include
#define ROW 20
#define COL 20
void main()
{
int a[ROW][COL],b[ROW][COL],c[ROW][COL];
int i=0,j=0,k,sum=0,m,n;
clrscr();
printf("\n enter the value for m\n");
scanf("%d",&m);
printf("\n enter the value for n\n");
scanf("%d",&n);
printf("\n enter the matrix A elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n the matrix A elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("\n enter the matrix B elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n the matrix B elements ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
printf("\n the product of matrices is as follows \n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
getch();
}
No comments:
Post a Comment