forked from rishabh-bansal/C-Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unionarray.c
71 lines (70 loc) · 1.18 KB
/
unionarray.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
#include<stdio.h>
#include<conio.h>
int main()
{
int n1,n2;
int a[20],b[20],c[20];
int i,j;
int d=0;
int e=0;
int g=0;
int f=0;
printf("enter a size of array 1: ");
scanf("%d",&n1);
for(i=0;i<n1;i++)
{
scanf("%d",&a[i]);
}
printf("enter a size of array 2: ");
scanf("%d",&n2);
for(i=0;i<n2;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n1;i++)
{
for(j=0;j<g;j++)
{
if(a[i]==c[j])
{
f=f+1;
}
}
if(f==0)
{
c[g]=a[i];
g=g+1;
}
else
{
f=0;
}
}
for(i=0;i<n2;i++)
{
for(j=0;j<n1+e;j++)
{
if(b[i]==c[j])
{
d=d+1;
}
}
if(d==0)
{
c[g+e]=b[i];
e=e+1;
}
else
{
d=0;
}
}
printf("\n");
printf("union of above two arrays is : ");
for(i=0;i<e+g;i++)
{
printf("%d ",c[i]);
}
printf("\n");
return 0;
}