20_10

Write a C program to perform Multiplication of two matrixes.

 Source code:

/*Multiplication of two matrixes. It is only possible if the first matrix of size i x j and other matrix of size j x k , where I, j and k are any positive integer. Three two dimensional matrices a, b and c each of size [3x3] will be considered here. Read the values of matrix a and matrix b, multiply and put it matrix c. Finally print the value of matrix c. */


#include<stdio.h>

int main()

{

  int a[3][3],b[3][3],c[3][3],i,j,k,sum=0,m=3,n=3,o=3,p=3;

printf("Enter 1st matrix: \n");

/* Read Matrix a */

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

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

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


printf("Enter 2nd matrix: \n");

/* Read Matrix b */

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

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

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

           

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

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

            c[i][j]=0;

      for(i=0;i<m;i++){ /* row of first matrix */

      for(j=0;j<p;j++){  /* column of second matrix */

            sum=0;

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

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

            c[i][j]=sum;

      }

      }

printf("The multiplication of two matrix is");

  for(i=0;i<m;i++){

      printf("\n");

      for(j=0;j<p;j++){

          printf("%d ",c[i][j]);

      }

  }

  return 0;

}

Output:

C program to perform Multiplication of two matrixes


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...