-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp4addOf2Matrix.cpp
More file actions
33 lines (27 loc) · 788 Bytes
/
p4addOf2Matrix.cpp
File metadata and controls
33 lines (27 loc) · 788 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
#include <iostream>
using namespace std;
int main() {
int a[2][2], b[2][2], sum[2][2];
// Input first matrix
cout << "Enter elements of first 2x2 matrix:\n";
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
cin >> a[i][j];
// Input second matrix
cout << "Enter elements of second 2x2 matrix:\n";
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
cin >> b[i][j];
// Add matrices
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
sum[i][j] = a[i][j] + b[i][j];
// Display result
cout << "Sum of matrices:\n";
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++)
cout << sum[i][j] << " ";
cout << endl;
}
return 0;
}