#include <iostream>
using namespace std;
class matrix
{
    int a[10][10],b[10][10],mul[10][10];
    int r1,r2,c1,c2;
    int i,j,k;
    public:
    void getrandc()
    {
        cout<<"\n Enter the Row Size for Matrix 1 : ";
        cin>>r1;
        cout<<"\n Enter the Column Size for Matrix 1 : ";
        cin>>c1;
        cout<<"\n Enter the Row Size for Matrix 2 : ";
        cin>>r2;
        cout<<"\n Enter the Column Size for Matrix 2 ";
        cin>>c2;
    }
    int check()
    {
        if(c1==r2)
            return 1;
        else
            return -1;
    }
    void getmatrix()
    {
        cout<<"\n Enter the "<<r1*c1<<" Elements for Matrix 1...\n";
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c1;j++)
            {
                cin>>a[i][j];
            }
        }
        cout<<"\n Enter the "<<r2*c2<<" Elements for Matrix 2...\n";
        for(i=0;i<r2;i++)
        {
            for(j=0;j<c2;j++)
            {
                cin>>b[i][j];
            }
        }
    }
    void multiply()
    {
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c2;j++)
            {
                for(k=0;k<c1;k++)
                {
                    mul[i][j]=mul[i][j]+a[i][k]*b[k][j];
                }
            }
        }
    }
    void display()
    {
        cout<<"\n The Matrix 1 is...\n";
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c1;j++)
            {
                cout<<a[i][j]<<"  ";
            }
            cout<<"\n";
        }
        cout<<"\n\n The Matrix 2 is...\n";
        for(i=0;i<r2;i++)
        {
            for(j=0;j<c2;j++)
            {
                cout<<b[i][j]<<"  ";
            }
            cout<<"\n";
        }
        cout<<"\n\n The Multiplied Matrix (Matrix 1 * Matrix 2) is...\n";
        for(i=0;i<r1;i++)
        {
            for(j=0;j<c2;j++)
            {
                cout<<mul[i][j]<<"  ";
            }
            cout<<"\n";
        }
    }
};
int main()
{
    int value;
    matrix obj;
    cout<<"\n -------------------------------------------";
    cout<<"\n            Matrix Multiplication.          ";
    cout<<"\n -------------------------------------------";
    obj.getrandc();
    value=obj.check();
    if(value==1)
    {
        obj.getmatrix();
        obj.multiply();
        obj.display();
    }
    else
    {
        cout<<"\n\n The Given Ranged Matrixes are not to Multiplication.";
    }
    cout<<"\n\n Program was Ended...";
    return 0;
}

Embed on website

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