forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnion.cpp
More file actions
35 lines (29 loc) · 733 Bytes
/
Union.cpp
File metadata and controls
35 lines (29 loc) · 733 Bytes
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
//C++ program to find the union of two arrays
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cout<<"Enter the size of first set: "<<endl;
cin>>n;
int m;
cout<<"Enter the size of second set: "<<endl;
cin>>m;
int arr[n];
cout<<"Enter the elements of first set: "<<endl;
for(int i=0; i<n; i++){
cin>>arr[i];
}
int brr[m];
cout<<"Enter the elements of second set: "<<endl;
for(int i=0; i<m; i++){
cin>>brr[i];
}
set<int> st;
for(int i=0; i<n; i++)
st.insert(arr[i]);
for(int i=0; i<m; i++)
st.insert(brr[i]);
for (auto itr = st.begin(); itr != st.end(); itr++)
cout << *itr << " ";
return 0;
}