## 14/03/2016

Check- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard Domain.

Solution:-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

class Matrix
{
public:
vector<vector<int> > a;

Matrix & operator + (const Matrix &y)
{
for (int m=0; m<y.a.size(); ++m)
{
for (int n=0; n<y.a.size(); ++n)
{
this->a[m][n] = this->a[m][n] + y.a[m][n];
}
}
return *this;
}

};

int main ()
{
int cases,k;
cin >> cases;

for(k=0;k<cases;k++)
{
Matrix x;
Matrix y;
Matrix result;
int n,m,i,j;

cin >> n >> m;

for(i=0;i<n;i++)
{
vector<int> b;
int num;

for(j=0;j<m;j++)
{
cin >> num;
b.push_back(num);
}
x.a.push_back(b);
}

for(i=0;i<n;i++)
{
vector<int> b;
int num;

for(j=0;j<m;j++)
{
cin >> num;
b.push_back(num);
}
y.a.push_back(b);
}

result = x+y;

for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout << result.a[i][j] << " ";
}
cout << endl;
}
}
return 0;

}

Output:-

Previous Post
Next Post

#### post written by: Ghanendra Yadav

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.