MATRIX ADDITION AND SUBTRACTION

Muthumari_B · updated October 03, 2021 · C++
// MATRIX ADDITION and SUBTRACTION ;


#include<iostream>
using namespace std;
class mat 
{
    int a[10][10],b[10][10],c[10][10],d[10][10],i,j,n;
    public:
    void getdata();
    void putdata();
};

 
void mat:: getdata()
{
    cout<<"\n Enter a Size Of Matrix : ";
    cin>>n;
    cout<<n<<endl;
    cout<<"\n First Matrix Elements : ";
    for(j=0;j<n;j++)
    {
        for(i=0;i<n;i++)
        {
            cin>>a[i][j];
        }
    }
    for(j=0;j<n;j++)
    {
        for(i=0;i<n;i++)
        {
            cout<<a[i][j]<<" ";
        }
    }  
    cout<<"\n Second Matrix Elements : ";
    for(j=0;j<n;j++)
    {
        for(i=0;i<n;i++)
        {
            cin>>b[i][j];
        }
    }
    for(j=0;j<n;j++)
    {
        for(i=0;i<n;i++)
        {
            cout<<b[i][j]<<" ";
        }
    }      
}    
    

void mat:: putdata() 
{
    cout<<"\n\n Matrix A : "<<endl;
    for(j=0;j<n;j++)
    {
        cout<<"\n";
        for(i=0;i<n;i++)
        {
            cout<<"\t"<<a[i][j];
        }
    }
    cout<<"\n\n Matrix B : "<<endl;
    for(j=0;j<n;j++)
    {
        cout<<"\n";
        for(i=0;i<n;i++)
        {
            cout<<"\t"<<b[i][j];
        }
    }
    cout<<"\n\n ADDITION of Two Matrices : MATRIX (A + B) "<<endl;
    for(j=0;j<n;j++)
    {
        cout<<"\n";
        for(i=0;i<n;i++)
        {
            cout<<"\t"<<a[i][j]+b[i][j];
        }
    }
    cout<<"\n\n SUBTRACTION of Two Matrices : MATRIX (A - B) "<<endl;
    for(j=0;j<n;j++)
    {
        cout<<"\n";
        for(i=0;i<n;i++)
        {
            cout<<"\t"<<a[i][j]-b[i][j];
        }
    }
}
int main()
{
    class mat m;
    m.getdata();
    m.putdata();
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.