google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to find the product of two matrices - 2nd puc computer science

Write a c program to find the product of two matrices

c program to find the product of two matrices,write a program to multiply two matrices,Write a program to find the product of two matrices in c

Write a c program to find the product of two matrices

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10][10],b[10][10],p[10][10],i,j,k,r1,c1,r2,c2;

clrscr();

printf("Enter the order of the first matrix\n");

scanf("%d%d",&r1,&c1);

printf("Enter the order of the second matrix\n");

scanf("%d%d",&r2,&c2);

if(c1==r2)

{

         printf("Enter the elements of first matrix\n");

         for(i=0;i<r1;i++)

         for(j=0;j<c1;j++)

         scanf("%d",&a[i][j]);

         printf("Enter the elements of second matrix\n");

         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++)

                  {

                  p[i][j]=0;

                  for(k=0;k<c1;k++)

                           p[i][j]=p[i][j]+a[i][k]*b[k][j];

                  }

printf("The resultant matrix is:\n");

for(i=0;i<r1;i++)

{

         for(j=0;j<c2;j++)

                  printf("%d\t",p[i][j]);

                  printf("\n");

}

}

else

printf("Matrices are not compatible");

getch();

}

/*Output:

 

run 1:

Enter the order of the first matrix

2

2

Enter the order of the second matrix

2

2

Enter the elements of first matrix

1 2

3 4

Enter the elements of second matrix

5 6

7 8

The resultant matrix is:

19      22

43      50

 

run 2:

Enter the order of the first matrix

2                                                                              

2                                                                              

Enter the order of the second matrix                                            

3                                                                              

3                                                                              

Matrices are not compatible 
Write a c program to find the product of two matrices Write a c program to find the product of two matrices Reviewed by Vision Academy on December 12, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.