-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW5p2.cpp
More file actions
48 lines (40 loc) · 1.05 KB
/
HW5p2.cpp
File metadata and controls
48 lines (40 loc) · 1.05 KB
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
43
44
45
46
47
48
#include <iostream>
using namespace std;
int main()
{
int r, c =0;
int MatA[4][5], MatB[4][5], sum[4][5], i, j;
// Storing elements of first matrix
cout<< "Matrix A:";
for(i = 0; i <= r; ++i)
for(j = 0; j < c; ++j)
{
MatA[i][j] = rand()% 20+1;
cout << MatA[i][j] << " ";
if(j == c - 1)
cout << endl;
}
// Storing elements of second matrix
for(i = 0; i <= r; ++i)
for(j = 0; j < c; ++j)
{
MatB[i][j] = rand() % 20+1;
cout << MatB[i][j] << " ";
if(j == c - 1)
cout << endl;
}
// Adding Two matrices
for(i = 0; i <= r; ++i)
for(j = 0; j < c; ++j)
sum[i][j] = MatA[i][j] + MatB[i][j];
// Displaying the resultant sum matrix.
cout << endl << "Sum of two matrix is: " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << sum[i][j] << " ";
if(j == c - 1)
cout << endl;
}
return 0;
}