#include <iostream>
using namespace std;
class matrix
{
    int a[10][10],b[10][10],d[10][10],i,j,r,c;
    public:
    void getdata();
    void add();
    void sub();
};
void matrix::getdata()
{
    cout<<"\nEnter the row and column:";
    cin>>r>>c;
    cout<<"\nEnter the elements for matrix a:";
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<"\nEnter the elements for matrix b:";
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            cin>>b[i][j];
        }
    }
}
void matrix::add()
{
    cout<<"\nMATRIX ADDITION";
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            d[i][j]=a[i][j]+b[i][j];
        }
    }
    for(i=0;i<r;i++)
    {
        cout<<"\n";
        for(j=0;j<c;j++)
        {
            cout<<"\t"<<d[i][j];
        }
    }
}
void matrix::sub()
{
    cout<<"\nMATRIX SUBTRACTION";
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            d[i][j]=a[i][j]-b[i][j];
        }
    }
    for(i=0;i<r;i++)
    {
        cout<<"\n";
        for(j=0;j<c;j++)
        {
            cout<<"\t"<<d[i][j];
        }
    }
}
int main()
{
    matrix m;
    m.getdata();
    m.add();
    m.sub();
    return 0;
}

Embed on website

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