Program to add matrix.

hi guys I am not getting the right result in the program as shown below, plz help why this is happening.

ALsO, I am not able to get into the if block that has the condition :
temp=="A",

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#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();
}
}
Topic archived. No new replies allowed.