-
Notifications
You must be signed in to change notification settings - Fork 0
/
Union of sets.c
61 lines (54 loc) · 1.22 KB
/
Union of sets.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
void findunion(int array1[], int array2[], int size1, int size2)
{
int i, j, k = 0;
int array3[100]={0};
for (i = 0; i < size1; i++)
{
for (j = 0; j < size2; j++)
{
array3[k] = array1[i];
k++;
array3[k] = array2[j];
k++;
}
}
for (i = 0; i < k; i++)
{
for (j = 0; j < k - 1; j++)
{
if (array3[j] > array3[j+1])
{
int temp = array3[j];
array3[j] = array3[j+1 ];
array3[j +1 ] = temp;
}
}
}
printf("Union of the array is : \n");
for (i = 0; i < k; i++)
{
int flag = 0;
for (j = 0; j < i; j++)
{
if (array3[i] == array3[j])
{
flag = 1;
break;
}
}
if (flag == 0)
{
printf("%d ", array3[i]);
}
}
}
int main()
{
int array1[] = {1, 2, 3, 4, 5, 6, 3, 2};
int array2[] = {1, 3, 5, 7};
int size1 = 8;
int size2 = 4;
findunion(array1, array2, size1, size2);
return 0;
}