forked from Ambika55/Hacktober-Fest-2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrices.cpp
122 lines (92 loc) · 2.29 KB
/
matrices.cpp
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
#include<iostream>
using namespace std;
class matrix{
private:
int m, n, c, d ,first[2][2],second[2][2], res[2][2];
int m2,n2;
public :
void getmatrixfirst(){
cout << "Enter the number of rows and columns of matrix of 1st";
cin >> m >> n;
cout << "Enter the elements of first matrix\n";
for ( c = 0 ; c < m ; c++ ){
for ( d = 0 ; d < n ; d++ ){
cin >> first[c][d];
}
}
}
void getsecondmatrix(){
cout << "Enter the number of rows and columns of 2nd matrix ";
cin >> m2 >> n2;
cout << "Enter the elements of second matrix\n";
for ( c = 0 ; c < m2 ;c++ ){
for ( d = 0 ; d < n2 ; d++ ){
cin >> second[c][d];
}
}
}
void getaddmat(){
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
res[c][d] = first[c][d] + second[c][d];
cout << "sum of entered matrices:-\n";
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
cout << res[c][d] << "\t";
cout << endl;
}
}
void getsubtr(){
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
res[c][d] = first[c][d] - second[c][d];
cout << "subtraction of entered matrices:-\n";
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
cout << res[c][d] << "\t";
cout << endl;
}
}
void gettranspose(){
for ( c = 0 ; c < m ; c++ ){
for ( d = 0 ; d < n ; d++ ){
res[c][d] = first[d][c] ;
}
}
cout << "transpose of entered matrices:-\n";
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
cout << res[c][d] << "\t";
cout << endl;
}
}
void getmult(){
for ( c = 0 ; c < m ; c++ ){
for ( d = 0 ; d < n2 ; d++ ){
res[c][d]=0;
for(int k=0;k<n2;k++){
res[c][d] += first[c][k] * second[k][c];
}
}
}
cout << "multiplication of entered matrices:-\n";
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n2 ; d++ )
cout << res[c][d] << "\t";
cout << endl;
}
}
};
int main(int argc,char** argv)
{ matrix m1;
m1.getmatrixfirst();
m1.getsecondmatrix();
m1.getaddmat();
m1.getsubtr();
m1.gettranspose();
m1.getmult();
}