-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_intersection.c
55 lines (47 loc) · 1.09 KB
/
array_intersection.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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int m,n,i,j,p=0,repeat=0,a[100],b[100],c[100],flag=0;
printf("Enter the number of elements in 1st array : ");
scanf("%d",&m);
printf("\nEnter the elements : \n");
for(i=0; i<m; i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter the number of elements in 2nd array : ");
scanf("%d",&n);
printf("\nEnter the elements : \n");
for(j=0; j<n; j++)
{
scanf("%d",&b[j]);
}
printf("\nINTERSECTION OF TWO ARRAYS : \n");
for (i=0; i<m; i++)
{
for (j=0; j<n; j++)
{
if(a[i]==b[j])
{
repeat=0;
for(int k=0; k<p; k++)
{
if(c[k]==b[j])
{
repeat=1;
break;
}
}
if (repeat==0)
{
c[p]=b[j];
}
p=p+1;
}
}
}
for (i=0; c[i]!='\0'; i++)
printf("%d",c[i]);
return 0;
}