0% found this document useful (0 votes)
48 views3 pages

C++ Program for Union of Two Sets

The document contains code to find the union of two sets by taking elements from two input arrays and outputting a combined list without duplicates. The code takes in two arrays as input, loops through to print non-duplicate elements from both arrays, and outputs the union of the two sets.

Uploaded by

Saleha Maham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

C++ Program for Union of Two Sets

The document contains code to find the union of two sets by taking elements from two input arrays and outputting a combined list without duplicates. The code takes in two arrays as input, loops through to print non-duplicate elements from both arrays, and outputs the union of the two sets.

Uploaded by

Saleha Maham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <iostream>

#include <stdio.h>

using namespace std;

void findUnion(int set1[], int set2[], int a,int b)

int i, j;

cout<<"Please enter the elements of first set: ";

for(i=0; i<4; i++)

cin>>set1[i];

cout<<"Please enter the elements of second set: ";

for(j=0; j<4; j++)

cin>>set2[j];

int i = 0, j = 0;

while (i < a && j < b)

if (set1[i] < set2[j])


cout << set1[i++] << " ";

else if (set2[j] < set1[i])

cout << set2[j++] << " ";

else

cout << set2[j++] << " ";

i++;

while(i < a)

cout << set1[i++] << " ";

while(j < b)

cout << set2[j++] << " ";

int set1[a];

int set2[b];
int a = sizeof(set1)/sizeof(set1[0]);

int b = sizeof(set2)/sizeof(set2[0]);

findUnion(set1, set2, a, b);

return 0;

You might also like