-
Notifications
You must be signed in to change notification settings - Fork 0
/
addMatrices.cpp
42 lines (37 loc) · 981 Bytes
/
addMatrices.cpp
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 mat1[2][3]; // Declare 1st matrix
int mat2[2][3]; // Declare 2nd matrix
int result[2][3]; // Declare result matrix
// Get values for 1st matrix
cout << " \n Enter values for 1st matrix ";
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> mat1[i][j];
}
}
// Get values for 2nd matrix
cout << " \n Enter values for 2nd matrix ";
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> mat2[i][j];
}
}
// Calculate(add) and display result matrix
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
result[i][j] = mat1[i][j] + mat2[i][j];
cout << " " << result[i][j];
}
cout << endl;
}
return 0;
}