-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix addition 2d.cpp
More file actions
104 lines (73 loc) · 1.78 KB
/
matrix addition 2d.cpp
File metadata and controls
104 lines (73 loc) · 1.78 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>
using namespace std;
int main()
{
//----------declare and initialization
int arr1[100][100];
int arr2[100][100];
int arr3[100][100];
int row,column;
cout<<"enter row of matrix:"<<endl;
cin>>row;
cout<<"enter column of matrix:"<<endl;
cin>>column;
//--------------------------------------------
cout<<"enter the value of arr1"<<endl;
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
cout<<"arr1["<<i<<"]["<<j<<"]="<<endl;
cin>>arr1[i][j];
}
}
//----------------------------------
cout<<"enter the value of arr2"<<endl;
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
cout<<"arr2["<<i<<"]["<<j<<"]="<<endl;
cin>>arr2[i][j];
}
}
//---------show entered matrix
cout<<" matrix1:"<<endl;
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
cout<<arr1[i][j]<<" ";
}
cout<<endl;
}
//---------show entered matrix
cout<<" matrix2:"<<endl;
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
cout<<arr2[i][j]<<" ";
}
cout<<endl;
}
//-------add 2 matrix------------
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
arr3[i][j]=arr1[i][j]+arr2[i][j];
}
}
//-----------------------------------------------------
cout<<"matrix after addition"<<endl;
for(int i=0; i<row; i++)
{
for(int j=0; j<column; j++)
{
cout<<arr3[i][j]<<" ";
}
cout<<endl;
}
return 0;
}