Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Matrix multiplication in c++

 c++ program to multiply matrices (two dimensional array), this program multiplies two matrices which will be entered by the user. Firstly user will enter the order of a matrix. If the entered orders of two matrix is such that they can't be multiplied then an error message is displayed on the screen.
You have already studied the logic to multiply them in Mathematics.
Matrices are frequently used while doing programming and are used to represent graph data structure, in solving system of linear equations and many more. Lot of research is being done on how to multiply matrices using minimum number of operations. You can also implement it using pointers.

Source Code:-

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
  int a[10][10],b[10][10],c[10][10],l,m,n,o,i,j,k;
  cout<<"Matrix Multiplication by-Tarun Rawat\n";
  again:
  cout<<"\nEnter Row & Column Of Matrix A \n";
  cin>>l>>m;
  cout<<"\nEnter Row & Column Of Matrix B \n";
  cin>>n>>o;
  if(m==n)
   {cout<<"Matrix Can Be Multiply \n";
   }
  else{ cout<<"Incorrect Matrix For Multiplication \n";
       goto again;
       }
  cout<<"\nEnter Elements Of Matrix A: \n";
  for(i=0;i<l;i++)
     { for(j=0;j<m;j++)
 {cin>>a[i][j];
 }
     }
  cout<<"\nEnter Elements Of Matrix B: \n";
    for(i=0;i<n;i++)
       { for(j=0;j<o;j++)
   {cin>>b[i][j];
   }
       }
    for(i=0;i<l;i++)
       {for(j=0;j<o;j++)
  {c[i][j]=0;
     for(k=0;k<m;k++)
 {c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
 }
  }
       }
   cout<<"\nMultiplication Of Matrix A & B:  ";
   for(i=0;i<l;i++)
      {cout<<"\n";
for(j=0;j<o;j++)
   { cout<<c[i][j]<<"  ";
   }
      }
getch();

}

2 comments:

Blogger Widgets

Find Us On Google, Just type - way2cplusplus -

If you have any questions on implementing or understanding this C++ Program , shoot me a comment and I'll be glad to help! :) :)