#include <iostream>
using namespace std;
class matrix
{
int i,j,row,column;
int first[10][10],second[10][10],add[10][10],sub[10][10];
public:
void randc()
{
cout<<"\n Enter the Row and Column size for the Matrixes : ";
cin>>row>>column;
}
void get_matrix1()
{
cout<<"\n Enter the "<<row*column<<" Elements of Matrix1 : \n";
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
cin>>first[i][j];
}
}
}
void get_matrix2()
{
cout<<"\n Enter the "<<row*column<<" Elements of Matrix2 : \n";
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
cin>>second[i][j];
}
}
}
void add_matrix()
{
cout<<"\n The Addition Matrix : \n";
for(i=0;i<row;i++)
{
cout<<"\t";
for(j=0;j<column;j++)
{
add[i][j]=first[i][j]+second[i][j];
cout<<add[i][j]<<" ";
}
cout<<"\n";
}
}
void sub_matrix()
{
cout<<"\n The Subtraction Matrix : \n";
for(i=0;i<row;i++)
{
cout<<"\t";
for(j=0;j<column;j++)
{
sub[i][j]=first[i][j]-second[i][j];
cout<<sub[i][j]<<" ";
}
cout<<"\n";
}
}
void display()
{
cout<<"\n The Matrix 1 is...\n";
for(i=0;i<row;i++)
{
cout<<"\t";
for(j=0;j<column;j++)
{
cout<<first[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n The Matrix 2 is...\n";
for(i=0;i<row;i++)
{
cout<<"\t";
for(j=0;j<column;j++)
{
cout<<second[i][j]<<" ";
}
cout<<"\n";
}
}
};
int main()
{
matrix obj;
cout<<"\n ------------------------------------------";
cout<<"\n Matrix Addition and Subtraction. ";
cout<<"\n ------------------------------------------";
obj.randc();
obj.get_matrix1();
obj.get_matrix2();
obj.display();
obj.add_matrix();
obj.sub_matrix();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: