-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUntitled-10.c
82 lines (81 loc) · 1.82 KB
/
Untitled-10.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<stdio.h>
void main()
{
int arr[100], brr[100], i, j, n, m, inter[100], uni[100], x=0, y=0, c1=0, c2;
printf("Enter the number of elements of Array 1 : ");
scanf("%d",&n);
printf("Enter the elements: \n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("Enter the number of elements of Array 2: ");
scanf("%d",&m);
printf("Enter the elements: \n");
for(j=0;j<m;j++)
scanf("%d",&brr[j]);
printf("\nArray 1:\n[ ");
for(i=0;i<n;i++)
printf("%d ",arr[i]);
printf("]\nArray 2:\n[ ");
for(j=0;j<m;j++)
printf("%d ",brr[j]);
printf("]\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(arr[i]==brr[j])
{
c1+=1;
inter[x]=arr[i];
x++;
}
}
}
for(x=0;x<c1;x++)
{
for(int s=x+1;s<c1;s++)
{
if(inter[x]==inter[s])
{
for(int t=s;t<c1-1;t++)
inter[t]=inter[t+1];
c1--;
s--;
}
}
}
printf("\nIntersection: [ ");
for(x=0;x<c1;x++)
printf("%d ",inter[x]);
printf("]\n");
for(i=0;i<n;i++)
{
uni[y]=arr[i];
y++;
}
y=n;
c2=n;
for(j=0;j<m;j++)
{
c2++;
uni[y]=brr[j];
y++;
}
for(y=0;y<c2;y++)
{
for(int u=y+1;u<c2;u++)
{
if(uni[y]==uni[u])
{
for(int v=u;v<c2-1;v++)
uni[v]=uni[v+1];
c2--;
u--;
}
}
}
printf("Union: [ ");
for(y=0;y<c2;y++)
printf("%d ",uni[y]);
printf("]");
}