We Offers

  • Basics of C Programming
  • Basics of C Graphics Programming
  • Simple and Effective tutorials
  • No. of Practical Examples
  • Online Support for User's Problems.

Multiplication of Two Matrix



                                          To preform multiplication two matrix we need two know about the way of multiplication in matrix. In matrix multiplication process as below :

For Example : 
                  We have two matrix A[2][2] and B[2][2], And we store the result in third matrix C[2][2]. Now when we performing multiplication we get the result in third matrix as follow.

C[0][0] = A[0][0] * B[0][0] + A[0][1] * B[1][0]

C[0][1] = A[0][0] * B[0][1] + A[0][1] * B[1][1]

C[0][2] = A[1][0] * B[0][0] + A[1][1] * B[1][0]

C[0][3] = A[1][0] * B[0][1] + A[1][1] * B[1][1]

C program to multiplication of two matrix


#include<stdio.h>

void main()
{
       int a[3][3],b[3][3],c[3][3];
       int i,j,k;
       clrscr();

       printf("Enter elements in First array : \n");
       for(i=0;i<3;i++)
       {
              for(j=0;j<3;j++)
              {
                     scanf("%d",&a[i][j]);
              }
       }

       printf("Enter elements in Second array : \n");

       for(i=0;i<3;i++)
       {
              for(j=0;j<3;j++)
              {
                     scanf("%d",&b[i][j]);
              }
       }

       printf("Matrix A\n");
       for(i=0;i<3;i++)
       {
              for(j=0;j<3;j++)
              {
                     printf("%d ",a[i][j]);
              }
              printf("\n");
       }

       printf("Matrix B\n");
       for(i=0;i<3;i++)
       {
              for(j=0;j<3;j++)
              {
                     printf("%d ",b[i][j]);
              }
              printf("\n");
       }

       for(i=0;i<3;i++)
       {
              for(j=0;j<3;j++)
              {
                   c[i][j]=0;
                   for(k=0;k<3;k++)
                   {
                        c[i][j]=c[i][j]+a[i][k]*b[k][j];
                   }
              }
       }

       printf("Multiplication of A & B Matrix : \n");
       for(i=0;i<3;i++)
       {
              for(j=0;j<3;j++)
              {
                     printf("%d ",c[i][j]);
              }
              printf("\n");
       }

       getch();
}


matrix_multiplication


0 comments:

Post a Comment