-
Notifications
You must be signed in to change notification settings - Fork 16
/
2dArrayoperations.cpp
83 lines (74 loc) · 1.11 KB
/
2dArrayoperations.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
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
/*2-D array initialization, take input, display output,
addition, subtraction*/
#include <iostream>
using namespace std;
int main()
{
int i,j,arrA[2][2],arrB[2][2];
int add[2][2],sub[2][2],mul[2][2];
cout<<"Enter the elements of array A :"<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cin>>arrA[i][j];
}
}
cout<<"Enter the elements of array B :"<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cin>>arrB[i][j];
}
}
cout<<endl<<"**Addition of 2-D array A and B : "<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
add[i][j] = arrA[i][j] + arrB[i][j];
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<add[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<"**Substraction of 2-D array A and B : "<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
sub[i][j] = arrA[i][j] - arrB[i][j];
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<sub[i][j]<<" ";
}
cout<<endl;
}
cout<<endl<<"**Multiplication of 2-D array A and B : "<<endl;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
mul[i][j] = arrA[i][j] * arrB[i][j];
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<mul[i][j]<<" ";
}
cout<<endl;
}
return 0;
}