#include <iostream>
using namespace std;
int main()
{
int rows, cols, i, j;
cout << "Enter the number of rows and columns of matrix: ";
cin >> rows >> cols;
int matrix1[rows][cols], matrix2[rows][cols], sum[rows][cols];
cout << "Enter the elements of first matrix:" << endl;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
cin >> matrix1[i][j];
}
}
cout << "Enter the elements of second matrix:" << endl;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
cin >> matrix2[i][j];
}
}
cout << "Sum of matrices:" << endl;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
sum[i][j] = matrix1[i][j] + matrix2[i][j];
cout << sum[i][j] << " ";
}
cout << endl;
}
return 0;
}
0 Comments