#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
//Enter the matrix A :
int m,n,p,q,i,j;
//Fetching information about structure.
cout<<"Enter the matrix A data :"<<endl;
cout<<"Enter the rows of matrix A :"<<endl;
cin>>m;
cout<<"Enter the columns of matrix A :"<<endl;
cin>>n;
cout<<endl;
cout<<"Now entering the data for matrix B : "<<endl;
cout<<"Enter the rows of matrix B :"<<endl;
cin>>p;
cout<<"Enter the columns of matrix B :"<<endl;
cin>>q;
//Declaring array i.e matrices
int ma[5][5];
int mb[5][5];
//ma[m][n];
//mb[p][q];
//Entering the values in the matrix :
//Entering value in Matrix A:
for( i=0;i<m;i++){
for( j=0;j<n;j++){
cout<<"Enter the values of Matrix For A :"<<endl;
cout<<"A["<<i+1<<"]["<<j+1<<"]"<<endl;
cin>>ma[i][j];
}
}
//Data input ends here for Matrix A
//Entering values in Matrix B:
for(i=0;i<p;i++){
for(j=0;j<q;j++){
cout<<"Enter the values of Matrix For B :"<<endl;
cout<<"A["<<i+1<<"]["<<j+1<<"]"<<endl;
cin>>ma[i][j];
}
}
//Date entry for B ends here.
//Checking if the A and B are addable or not.
char temp[5];
int mc[5][5];
if((m==p)&&(n==q)){
//mc[m][n];
cout<<endl<<"Matrix A and B can be added and subtracted"<<endl;
cout<<endl<<"Do you want to add the matrix or subtract the matrix."<<endl<<"Press A for addition and S(AB) for subtraction "<<endl<< "where S(AB) stands to subtract B from A and S(BA) stands for subtracting A from B."<<endl;
cin>>temp;
cout<<"HERE IS IT :"<<temp;
if(temp=="A"){
cout<<"Adding ";
for(int q=0;q<m;q++){
for(int w=0;w<n;w++){
mc[q][w]=ma[q][w]+mb[q][w];
}}
}
if(temp=="S(AB)"){
for( i=0;i<m;i++){
for( j=0;j<n;j++){
mc[i][j]=mb[i][j]-ma[i][j];
}}
}
if(temp=="S(BA)"){
for( i=0;i<m;i++){
for( j=0;j<n;j++){
mc[i][j]=ma[i][j]-mb[i][j];
}}
}
cout<<"Matrix C is as :"<<endl<<endl;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cout<<mc[i][j]<<" ";
}
cout<<endl;
}
getch();
}
}