Skip to content

Commit 276892d

Browse files
committed
New Program Added
1 parent 6f2a09a commit 276892d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

AddTwoMatrices.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
7+
8+
cout << "Enter number of rows (between 1 and 100): ";
9+
cin >> r;
10+
cout << "Enter number of columns (between 1 and 100): ";
11+
cin >> c;
12+
13+
cout << "\nEnter elements of First matrix:\n";
14+
15+
for (i = 0; i < r; ++i)
16+
for (j = 0; j < c; ++j)
17+
{
18+
cout << "Enter element a" << i + 1 << j + 1 << ": ";
19+
cin >> a[i][j];
20+
}
21+
22+
cout << "Enter elements of Second matrix:\n";
23+
for (i = 0; i < r; ++i)
24+
for (j = 0; j < c; ++j)
25+
{
26+
cout << "Enter element a" << i + 1 << j + 1 << ": ";
27+
cin >> b[i][j];
28+
}
29+
30+
// Adding Two matrices
31+
32+
for (i = 0; i < r; ++i)
33+
for (j = 0; j < c; ++j)
34+
{
35+
sum[i][j] = a[i][j] + b[i][j];
36+
}
37+
38+
// Displaying the result
39+
cout << "\nSum of two matrix is: \n\n";
40+
41+
for (i = 0; i < r; ++i)
42+
for (j = 0; j < c; ++j)
43+
{
44+
45+
cout << "\t" << sum[i][j];
46+
47+
if (j == c - 1)
48+
{
49+
cout << "\n\n";
50+
}
51+
}
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)