-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathintersection_dynamic.cpp
58 lines (50 loc) · 1.04 KB
/
intersection_dynamic.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
#include <iostream>
using namespace std;
int main()
{
cout << "Enter size of SET A\n";
int n1;
cin >> n1;
cout << "Enter size of SET B\n";
int n2;
cin >> n2;
int *setA = (int *)(malloc(n1 * sizeof(int)));
int *setB = (int *)(malloc(n2 * sizeof(int)));
cout << "Enter elements in SET A\n";
for (int i = 0; i < n1; i++)
{
cin >> setA[i];
}
cout << "Enter elements in SET B\n";
for (int j = 0; j < n2; j++)
{
cin >> setB[j];
}
if (n1 > n2)
{
for (int i = 0; i < n2; i++)
{
for (int j = 0; j < n1; j++)
{
if (setB[i] == setA[j])
{
cout << setB[i] << " ";
}
}
}
}
else
{
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n2; j++)
{
if (setA[i] == setB[j])
{
cout << setA[i] << " ";
}
}
}
}
return 0;
}