Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
        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;
}