6) Write a program to add and subtract two matrix

Anonymous School

            (Minds of Hacker)

--------------------------------


 Write a program to add and subtract two matrix


C++ Practical



#include<iostream>
using namespace std;
int main()
{
    int m1[3][3], m2[3][3],add[3][3],sub[3][3];
    cout<<"Enter the values for 3d first matrix\n";
    for(int i=0i<3i++)
    {
        for(int j=0j<3j++)
        {
            cin>>m1[i][j];
        }
    }

     cout<<"Enter the values for 3d seond matrix\n";
    for(int i=0i<3i++)
    {
        for(int j=0j<3j++)
        {
            cin>>m2[i][j];
        }
    }

    for(int i=0i<3i++)
    {
        for(int j=0j<3j++)
        {
            add[i][j]=m1[i][j]+m2[i][j];
        }
    }

    for(int i=0i<3i++)
    {
        for(int j=0j<3j++)
        {
            sub[i][j]=m1[i][j]-m2[i][j];
        }
    }

    cout<<"\n\nAddition of Matrix\n";
     for(int i=0i<3i++)
    {
        for(int j=0j<3j++)
        {
            cout<<add[i][j]<<" ";
        }
        cout<<"\n";
    }
    cout<<"\n\nsubtraction of Matrix\n";
     for(int i=0i<3i++)
    {
        for(int j=0j<3j++)
        {
            cout<<sub[i][j]<<" ";
        }
        cout<<"\n";
    }

    


}

 


Output:


Enter the values for 3d first matrix 1 2 3 3 4 5 6 7 8 Enter the values for 3d seond matrix 9 10 11 12 13 14 15 16 17 Addition of Matrix 10 12 14 15 17 19 21 23 25 subtraction of Matrix -8 -8 -8 -9 -9 -9 -9 -9 -9



 *******************Don't Make Learning Hard*****************



Follow us on :-

1) YouTube Channel :- Click Here

2) Blog                     :- Click Here


NextGen Digital... Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...