-
Notifications
You must be signed in to change notification settings - Fork 0
/
union_sets.c
56 lines (45 loc) · 953 Bytes
/
union_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
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],i,c[10],j,k=0,n1,n2;
printf("Enter number of element of set A\n");
scanf("%d",&n1);
printf("Enter the element of set A \n");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
printf("Enter number of element of set B\n");
scanf("%d",&n2);
printf("Enter the element of set B \n");
for(i=0;i<n2;i++)
scanf("%d",&b[i]);
for(i=0;i<n1;i++)
{
for(j=0;j<k;j++)
{
if(c[j]==a[i])
break;
}
if(j==k)
{
c[k]=a[i];
k++;
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<k;j++)
{
if(c[j]==b[i])
break;
}
if(j==k)
{
c[k]=b[i];
k++;
}
}
printf("Union of set A and B is:-\n");
for(i=0;i<k;i++)
printf("%d ",c[i]);
}