forked from DPrinceKumar/HacktoberFest2020-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixcalculation
231 lines (189 loc) · 5.18 KB
/
matrixcalculation
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <iostream>
using namespace std;
class matrix
{
public:
void addition();
void substraction();
void multiplication();
void transpose();
};
void matrix::addition()
{
int a[100][100];
int b[100][100];
int sum[100][100];
int rows;
int coloum;
cout<<"*****WELCOME TO THE ADDITION OF MATRIX*****\n";
cout<<"please enter the no of rows of first matrix\n";
cin>>rows;
cout<<"please enter the coloums of first matrix\n";
cin>>coloum;
for (int i=0;i<rows;++i)
for (int j=0;j<coloum;++j)
{
cout<<"please enter the element "<<i+1<<","<<j+1<<"\n";
cin>>a[i][j];
}
cout<<"please enter the no of rows of second matrix\n";
cin>>rows;
cout<<"please enter the coloums of second matrix\n";
cin>>coloum;
for (int i=0;i<rows;++i)
for (int j=0;j<coloum;++j)
{
cout<<"please enter the element "<<i+1<<","<<j+1<<"\n";
cin>>b[i][j];
}
for (int i=0;i<rows;++i)
for (int j=0;j<coloum;++j)
sum[i][j]=a[i][j]+b[i][j];
cout<<"the addition of two matrix is "<<"\n";
for (int i=0;i<rows;++i){
for (int j=0;j<coloum;++j)
cout<<sum[i][j]<<" ";
cout<<"\n";
}
}
void matrix::substraction()
{
int a[100][100];
int b[100][100];
int sum[100][100];
int rows;
int coloum;
cout<<"*****WELCOME TO THE SUBSTRACTION*****\n";
cout<<"please enter the no of rows of first matrix\n";
cin>>rows;
cout<<"please enter the coloums of first matrix\n";
cin>>coloum;
for (int i=0;i<rows;++i)
for (int j=0;j<coloum;++j)
{
cout<<"please enter the element "<<i+1<<","<<j+1<<"\n";
cin>>a[i][j];
}
cout<<"please enter the no of rows of second matrix\n";
cin>>rows;
cout<<"please enter the coloums of second matrix\n";
cin>>coloum;
for (int i=0;i<rows;++i)
for (int j=0;j<coloum;++j)
{
cout<<"please enter the element "<<i+1<<","<<j+1<<"\n";
cin>>b[i][j];
}
for (int i=0;i<rows;++i)
for (int j=0;j<coloum;++j)
sum[i][j]=a[i][j]-b[i][j];
cout<<"the substraction of two matrix is "<<"\n";
for (int i=0;i<rows;++i){
for (int j=0;j<coloum;++j)
cout<<sum[i][j]<<" ";
cout<<"\n";
}
}
void matrix::multiplication()
{
int row1;
int row2;
int coloum1;
int coloum2;
int a[100][100];
int b[100][100];
int mult[100][100];
cout<<"******WELCOME TO THE MULTIPLICATION**********\n";
cout<<"please enter the no of rows of first matrix \n";
cin>>row1;
cout<<"please enter the no of coloums of first matrix \n";
cin>>coloum1;
for (int i=0;i<row1;++i)
for(int j=0;j<coloum1;++j)
{
cout<<"please enter the values of "<<i+1<<","<<j+1<<"\n";
cin>>a[i][j];
}
cout<<"please enter the no of rows of second matrix \n";
cin>>row2;
cout<<"please enter the no of coloums of second matrix \n";
cin>>coloum2;
for (int i=0;i<row2;++i)
for(int j=0;j<coloum2;++j){
cout<<"please enter the values of "<<i+1<<","<<j+1<<"\n";
cin>>b[i][j];
}
for (int i=0;i<row1;++i)
for(int j=0;j<coloum2;++j)
mult[i][j]=0;
for (int i=0;i<row1;++i)
for(int j=0;j<coloum2;++j)
for(int k=0;k<coloum2;++k)
{
mult[i][j]=a[i][k]*b[k][j];
}
cout<<"the multiplication is \n";
for (int i=0;i<row1;++i){
for(int j=0;j<coloum2;++j)
cout<<mult[i][j]<<" ";
cout<<"\n";
}
}
void matrix::transpose()
{
int row;
int coloum;
int a[100][100];
int t[100][100];
cout<<"*****WELCOME TO THE TRANSPOSE OF MATRIX*****\n";
cout<<"please enter the no of rows\n";
cin>>row;
cout<<"please enter the value of coloum\n";
cin>>coloum;
for(int i=0;i<row;++i)
for (int j=0;j<coloum;++j)
{
cout<<"please enter the elements "<<i+j<<","<<j+1<<"\n";
cin>>a[i][j];
}
cout<<"your inputed matrix is \n";
for(int i=0;i<row;++i)
{
for(int j=0;j<coloum;++j)
cout<<a[i][j]<<" ";
cout<<"\n";
}
for (int i = 0; i < row; ++i)
for (int j = 0; j < coloum; ++j) {
t[j][i] = a[i][j];
}
cout<<"the transpose matrix is\n";
for(int i=0;i<row;++i)
{
for(int j=0;j<coloum;++j)
cout<<t[i][j]<<" ";
cout<<"\n";
}
}
int main()
{ int ch;
cout<<"*****WELCOME*****\n";
cout<<" 1: for addition of matrix\n 2: for substraction of matrix\n 3: multiplication of matrix\n 4: transpose of matrix\n 5: to exit\n";
cout<<"please enter your choice\n";
cin>>ch;
matrix obj;
switch (ch)
{
case 1: obj.addition();
break;
case 2: obj.substraction();
break;
case 3: obj.multiplication();
break;
case 4: obj.transpose();
break;
case 5: exit;
default :cout<<"invalid choice\n";
break;
}
}