Skip to content

Instantly share code, notes, and snippets.

@suryansh011
Created October 11, 2021 12:24
Show Gist options
  • Save suryansh011/3001261412402a56d5548c11dc18e54b to your computer and use it in GitHub Desktop.
Save suryansh011/3001261412402a56d5548c11dc18e54b to your computer and use it in GitHub Desktop.
Union of Two Sets
/* WAP in 'C' to find out the union of two set */
#include <stdio.h>
int main() {
int i, j, k = 0; /* Counters */
int a[] = {1, 3, 5, 7, 9, 11};
int b[] = {2, 4, 6, 12, 14, 16, 18, 8, 10, 12, 14, 16, 18, 20};
int r[99] = {};
int a_size = sizeof(a)/sizeof(a[0]);
int b_size = sizeof(b)/sizeof(b[0]);
for (i = 0; i < a_size; i++) {
for (j = 0; j < k; j++) {
if(a[i] == r[j]) {
break;
}
}
if (j == k) {
r[k] = a[i];
k++;
}
}
for (i = 0; i < b_size; i++) {
for (j = 0; j < k; j++) {
if(b[i] == r[j]) {
break;
}
}
if (j == k) {
r[k] = b[i];
k++;
}
}
for (i = 0; i < k; i++)
printf("%d ", r[i]);
printf("\n\nSURYANSH SINGH SHISHODIA\n2001641520055\nPSIT-CS-II-AI");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment