-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2D array add & subtract
59 lines (58 loc) · 1.26 KB
/
2D array add & subtract
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
#include<iostream>
using namespace std;
int main()
{
int a[5][5],b[5][5],c[5][5];
int i,j,m,n,x,y;
cout<<"enter rows and column of a : ";
cin>>n>>m;
cout<<"enter rows and column of b : ";
cin>>x>>y;
if(n==x && m==y)
{
cout<<"enter elements of a .."<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
cout<<"\nenter element of b .."<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
cin>>b[i][j];
}
}
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
cout<<"addition is .."<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
cout<<c[i][j]<<" ";
cout<<endl;
}
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
c[i][j]=a[i][j]-b[i][j];
}
cout<<"subtraction is .."<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
cout<<c[i][j]<<" ";
cout<<endl;
}
}
else
cout<<"\nAddition and Substraction is not possible";
}