-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.cpp
47 lines (41 loc) · 875 Bytes
/
matrix.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
#include <bits/stdc++.h>
using namespace std;
class Matrix
{
vector<vector<int>> mat;
public:
Matrix(int a = 0) : mat(vector<vector<int>>(10, vector<int>(10, a)))
{
}
Matrix operator+(Matrix m)
{
Matrix res;
for (int i = 0; i < this->mat.size(); i++)
{
for (int j = 0; j < this->mat[i].size(); j++)
res.mat[i][j] = this->mat[i][j] + m.mat[i][j];
}
return res;
}
void display()
{
for (vector<int> row : mat)
{
for (int e : row)
cout << e << " ";
cout << endl;
}
}
};
int main()
{
Matrix m1(10);
Matrix m2(20);
Matrix m3 = m1 + m2;
m1.display();
cout << "=========================\n";
m2.display();
cout << "=========================\n";
m3.display();
return 0;
}