# Untitled

unknown
plain_text
a year ago
1.4 kB
1
Indexable
Never
#include <iostream>
using namespace std;

// Function to display the intersection of two sets
void displayIntersection(int set1[], int size1, int set2[], int size2) {
int intersection[100];  // Assuming a maximum size for the intersection array

// Find the common elements in set1 and set2
int k = 0;
for (int i = 0; i < size1; i++) {
for (int j = 0; j < size2; j++) {
if (set1[i] == set2[j]) {
intersection[k++] = set1[i];
break;
}
}
}

// Display the intersection elements
cout << "Intersection of the sets: ";
for (int i = 0; i < k; i++) {
cout << intersection[i] << " ";
}
cout << endl;
}

int main() {
int set1[100];  // Assuming a maximum size for set1
int set2[100];  // Assuming a maximum size for set2
int size1, size2;

// Input set 1
cout << "Enter the number of elements for set 1: ";
cin >> size1;
cout << "Enter the elements of set 1: ";
for (int i = 0; i < size1; i++) {
cin >> set1[i];
}

// Input set 2
cout << "Enter the number of elements for set 2: ";
cin >> size2;
cout << "Enter the elements of set 2: ";
for (int i = 0; i < size2; i++) {
cin >> set2[i];
}

// Display the intersection of the sets
displayIntersection(set1, size1, set2, size2);

return 0;
}