Wednesday, 27 September 2017

Write a program to find the product of two matrices entered by the user at the time of compilation of program.

The steps to implement program are as follow:

// Here include header file variables and matrix declaration

#include<stdio.h>
#include<conio.h>
void main()
{
int  x[4][4], y[4][4], z[4][4], i, j, k;
clrscr();

// From here you enter the element into the matrix x[4][4]

printf (“Enter element of first matrix x[4][4]”);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
scanf(“%d”,&x[i][j]);
}


// From here you enter the element into the matrix y[4][4]

printf("Enter element of second matrix y[4][4]");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
          {
scanf(“%d”,&y[i][j]);
}

// logic for finding the product of the two matrix x[4][4] and y[4][4] and then stored it in z[4][4]

for (i=0;i<4,i++)
{ for(k=0;k<4;k++)
{
z[i][k]=0;
for(j=0;j<4;j++)
z[i][k]=z[i][k]+x[i][ j ]*y[ j ][k];
            }
}

// This particular code is used to display the result stored in matrix z[4][4]

printf (“Result of Multiplication\n”);
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf(“%d”,z[i][j]);
}
printf(“\n”);
  }
getch();
}

*****************************************



Thanks 
Mukesh Rajput


No comments:

Post a Comment

Thanks
Mukesh Rajput