Created
October 11, 2021 12:24
-
-
Save suryansh011/3001261412402a56d5548c11dc18e54b to your computer and use it in GitHub Desktop.
Union of Two Sets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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