Untitled
unknown
plain_text
2 years ago
1.1 kB
3
Indexable
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;
}
Editor is loading...