forked from HemangTheHuman/hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_add.cpp
More file actions
42 lines (41 loc) · 908 Bytes
/
matrix_add.cpp
File metadata and controls
42 lines (41 loc) · 908 Bytes
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
# include <iostream>
using namespace std;
int main()
{
int i, j, n, m, a[10][10], b[10][10], c[10][10];
cout << "Enter the number of rows and columns of the matrix: ";
cin >> n >> m;
cout << "Enter the elements of the first matrix: ";
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
cout << "Enter the elements of the second matrix: ";
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> b[i][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
c[i][j] = a[i][j] + b[i][j];
}
}
cout << "The sum of the two matrices is: " << endl;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cout << c[i][j] << " ";
}
cout << endl;
}
return 0;
}