Skip to content

Commit 876c536

Browse files
Create Addition of two matrices ussing array.cpp
1 parent 3a2c6c7 commit 876c536

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* C++ Program to Add Two Matrices using array */
2+
3+
#include<iostream>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
9+
int arr1[5][5], arr2[5][5], arr3[5][5], sub, i, j,m,n;
10+
11+
cout<<"Enter size of matrix ( Max:5 ) :: ";
12+
cin>>m;
13+
cout<<"\nEnter Elements to Matrix A Below :: \n";
14+
15+
for(i=0;i<m;i++)
16+
{
17+
for(j=0;j<m;++j)
18+
{
19+
cout<<"\nEnter arr1["<<i<<"]["<<j<<"] Element :: ";
20+
cin>>arr1[i][j];
21+
}
22+
23+
}
24+
25+
cout<<"\nEnter Elements to Matrix B Below :: \n";
26+
27+
for(i=0;i<m;i++)
28+
{
29+
for(j=0;j<m;++j)
30+
{
31+
cout<<"\nEnter arr2["<<i<<"]["<<j<<"] Element :: ";
32+
cin>>arr2[i][j];
33+
}
34+
35+
}
36+
37+
38+
cout<<"\nAdding Matrix ( A + B ) ..... \n";
39+
for(i=0; i<m; i++)
40+
{
41+
for(j=0; j<m; j++)
42+
{
43+
arr3[i][j]=arr1[i][j]+arr2[i][j];
44+
}
45+
}
46+
47+
cout<<"\nAfter Addition, Matrix C is :: \n";
48+
49+
for (i = 0; i < m; ++i)
50+
{
51+
for (j = 0; j < m; ++j)
52+
{
53+
cout<<"\t"<<arr3[i][j];
54+
}
55+
printf("\n\n");
56+
}
57+
58+
return 0;
59+
}

0 commit comments

Comments
 (0)