Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class matrice {
- public:
- vector<vector<int>> a;
- int line, coloana;
- friend matrice operator+(matrice m1, matrice m2);
- void afisare(matrice m);
- };
- matrice operator+(matrice m1, matrice m2) {
- matrice s;
- s.line = m1.line;
- s.coloana = m1.coloana;
- for (int i = 0; i < m1.a.size(); i++) {
- vector<int> temp;
- for (int j = 0; j < m1.a[i].size(); j++) {
- temp.push_back(m1.a[i][j] + m2.a[i][j]);
- }
- s.a.push_back(temp);
- }
- return s;
- }
- void afisare(matrice m) {
- for (int i = 0; i < m.a.size(); i++) {
- for (int j = 0; j < m.a[i].size(); j++) {
- cout << m.a[i][j] << " ";
- }
- cout << endl;
- }
- }
- int main() {
- // mesaj citire matrice 1
- matrice m1;
- cin >> m1.line >> m1.coloana;
- for (int i = 0; i < m1.line; i++) {
- vector<int> aux;
- for (int j = 0; j < m1.coloana; j++) {
- int n;
- cin >> n;
- aux.push_back(n);
- }
- m1.a.push_back(aux);
- }
- // mesaj citire matrice 2
- matrice m2;
- cin >> m2.line >> m2.coloana;
- for (int i = 0; i < m2.line; i++) {
- vector<int> aux;
- for (int j = 0; j < m2.coloana; j++) {
- int n;
- cin >> n;
- aux.push_back(n);
- }
- m2.a.push_back(aux);
- }
- // mesaj afisare rezultat adunare matrice 1 + matrice 2
- matrice m;
- m = m1 + m2;
- afisare(m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement