#include <iostream>
using namespace std;
class matrix
{
  int a[10][10],b[10][10],c[10][10],i,j,k,r1,r2,c1,c2,d=0;
  public:
  void getdata()
  {
     cout<<"\nEnter a row size for matrix a:";
     cin>>r1;
     cout<<"\nEnter a column size for matrix a:";
     cin>>c1;
     cout<<"\nEnter a row size for matrix b:";
     cin>>r2;
     cout<<"\nEnter a column size for matrix b:";
     cin>>c2;
  }
  void multi()
  {
    if(c1==r2)
     {
       cout<<"\n\nEnter the number for matrix a:"<<endl;
        for(i=0;i<r1;i++)
        {
         for(j=0;j<c1;j++)
         {
             cin>>a[i][j];
         }
        }
        cout<<"\nEnter the number for matrix b:"<<endl;
        for(i=0;i<r2;i++)
        {
         for(j=0;j<c2;j++)
         {
             cin>>b[i][j];
         }
        }
        for(i=0;i<r1;i++)
        {
         for(j=0;j<c2;j++)
         {
             for(k=0;k<c1;k++)
             {
                 d+=a[i][k]*b[k][j];
             }
             c[i][j]=d;
             d=0;
          }
         }
        cout<<"\nMATRIX A:";
        for(i=0;i<r1;i++)
        {
         cout<<"\n";
        for(j=0;j<c1;j++)
         {
          cout<<"\t"<<a[i][j];
         }
        }
        cout<<"\nMATRIX B:";
        for(i=0;i<r2;i++)
        {
           cout<<"\n";
         for(j=0;j<c2;j++)
         {
          cout<<"\t"<<b[i][j];
         }
        }
        cout<<"\n MATRIX MULTIPLICATION";
        for(i=0;i<r1;i++)
        {
           cout<<"\n";
        for(j=0;j<c2;j++)
          {
            cout<<"\t"<<c[i][j];
          }
        }
      }
    else 
    cout<<"\n\nThe Matrix Multiplication is impossible"<<endl;
  }
};
int main()
{
    cout<<"\nMATRIX MULTIPLICATION";
    cout<<"\n_____________________";
    matrix m;
    m.getdata();
    m.multi();
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: