1.intersection and Union of Two Sets Using 1-D Array PDF
1.intersection and Union of Two Sets Using 1-D Array PDF
Code:
#include <iostream>
int main() {
// Input set1
// Input set2
// Intersection
for (int i = 0; i < n1; i++) {
if (set1[i] == set2[j]) {
intersection[intersection_size++] = set1[i];
break;
// Union
union_set[union_size++] = set1[i];
if (set2[i] == union_set[j]) {
found = true;
break;
if (!found) {
union_set[union_size++] = set2[i];
// Output intersection
// Output union
cout << "Union: ";
return 0;
Input:
Enter the number of elements in set1: 5
Enter the elements of set1: 1 3 5 7 9
Enter the number of elements in set2: 4
Enter the elements of set2: 2 4 6 8
Output:
Intersection: (Null)
Union: 1 3 5 7 9 2 4 6 8
Since the two sets have no elements in common, the intersection is an empty set. The union
contains all the elements from both sets.