-
Notifications
You must be signed in to change notification settings - Fork 2
/
q9.cpp
43 lines (36 loc) · 997 Bytes
/
q9.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
43
#include <iostream>
using namespace std;
int main()
{
int m, n, p, q, i, j, A[5][5], B[5][5], C[5][5];
cout << "Enter rows and column of matrix A : ";
cin >> m >> n;
cout << "Enter rows and column of matrix B : ";
cin >> p >> q;
if ((m != p) && (n != q))
{
cout << "Matrices cannot be added!";
exit(0);
}
cout << "Enter elements of matrix A : ";
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
cin >> A[i][j];
cout << "Enter elements of matrix B : ";
for (i = 0; i < p; i++)
for (j = 0; j < q; j++)
cin >> B[i][j];
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
C[i][j] = A[i][j] + B[i][j];
cout << "Sum of matrices\n";
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
cout << C[i][j] << " ";
cout << "\n";
}
cout<<endl;
system("pause");
return 0;
}