forked from suman-shah/c-program-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comm.c
48 lines (43 loc) · 1.04 KB
/
comm.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
#include <stdio.h>
void main()
{
int a[100], b[100], com[100];
int n1, n2;
printf("Enter the no of elements in A:\n");
scanf("%d", &n1);
printf("Enter the elements in A:\n");
for (int i = 0; i < n1; i++)
scanf("%d", &a[i]);
printf("Enter the no of elements in B:\n");
scanf("%d", &n2);
printf("Enter the elements in B:\n");
for (int i = 0; i < n2; i++)
scanf("%d", &b[i]);
int i,j,m,k = 0,flag=0;
for (i = 0; i < n1; i++)
{
for (j = 0; j < n2; j++)
{
flag=0;
if (a[i] == b[j])
{
for(m=0;m<n1;m++)
{
if(com[m]==a[i])
{
flag=1;
}
}
if (flag==0)
{
com[k] = a[i];
k++;
}
}
}
}
printf("Intersection of two sets is : ");
for (int i = 0; i < k; i++)
printf("%d ", com[i]);
printf("\n");
}