forked from ishita0302/Code-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Union & Intersection of 2 sets.c
58 lines (51 loc) · 1.14 KB
/
Union & Intersection of 2 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
#include <stdio.h>
int main()
{
int a[10],b[10],c[20],n1,n2,i,j,f=0;
printf("enter no. of elements in A: ");
scanf("%d", &n1);
printf("\n enter no. of elements in B: ");
scanf("%d", &n2);
printf("\n enter elements of A: ");
for(i=0;i<n1;i++)
{ scanf("%d", &a[i]);}
printf("\n enter elements of B: ");
for(i=0;i<n2;i++)
{ scanf("%d", &b[i]);}
printf("set A: ");
for(i=0;i<n1;i++)
{ printf("%d \t", a[i]);}
printf("\n set B: ");
for(i=0;i<n2;i++)
{ printf("%d \t", b[i]);}
//intersection
printf("intersection is: ");
for(i=0;i<n1;i++)
{ for(j=0;j<n2;j++)
{ if(a[i]==b[j])
{
printf("%d ",a[i]);
break;
}
}
}
//union
printf("union is: ");
for(i=0;i<n1;i++)
{ printf("%d ", a[i]);}
for(int i=0;i<n2;i++)
{
for(int j=0;j<n1;j++)
{
if(b[i]==a[j])
{
f=1;
break;
}
}
if(f==0)
printf("%d ", b[i]);
f=0;
}
return 0;
}