Two-dimensional arrays: matrix addition

#include "stdafx.h"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
       int m, n, a, b, firstmat[2][2], secondmat[2][2], sum[2][2];
       cout << "Enter a number of rows and columns";
       cin >> m >> n;
       cout << "Enter the elements of the first matrix";
       for (a = 0; a < m; a++)
             for(b = 0; b < n; b++)
                    cin >> firstmat[a][b];
       for(a = 0; a < m; a++)
             for(b = 0; b < m; b++)
                    cout << "First matrix["<< a<<"]["<< b <<"]= " << firstmat[a][b] << "\n";
       cout << "Enter the elements of the second matrix";
       for(a = 0; a < m; a++)
             for(b = 0; b < n; b++)
                    cin >> secondmat[a][b];
       for(a = 0; a < m; a++)
       for(b = 0; b < m; b++)
             cout << "First matrix["<< a<<"]["<< b <<"]= " << firstmat[a][b] << "\n";
       cout << " The result of firstmat["<<a<<"]["<<b<<"] + secondmat["<<a<<"]["<< b <<"] = " << "\n";
       for(a = 0; a < m; a++)
             for(b = 0; b < n; b++)
                    sum[a][b] = firstmat[a][b]+secondmat[a][b];
       for(a = 0; a < m; a++)
             for(b = 0; b < n; b++)
                    cout << sum[a][b] << "\n";
       system("pause");
       return 0;

}
Share on Google Plus