-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset.c
112 lines (86 loc) · 2.06 KB
/
set.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <stdlib.h>
int a[20],b[20],c[20];
void set_union(int a[],int b[],int m){
printf("after Union operation\n");
for(int i=0;i<m;i++){
c[i]=a[i]||b[i];
printf("%d\t",c[i]);
}
return;
}
void set_intersection(int a[],int b[],int m){
printf("after intersection operation\n");
for(int i=0;i<m;i++){
c[i]=a[i]&&b[i];
printf("%d\t",c[i]);
}
return;
}
void set_difference(int a[],int b[],int m){
printf("after Difference operation\n");
for(int i=0;i<m;i++){
c[i]=!b[i]&&a[i];
printf("%d\t",c[i]);
}
return;
}
void main(){
int m,n,p;
printf("enter the size of 1st set\n");
scanf("%d",&m);
printf("enter the zeros and ones based on condition\n");
for(int i=0;i<m;i++){
main:
scanf("%d",&p);
if (p==0 || p==1){
a[i]=p;
}
else{
printf("set only accept 0's and 1's please enter a valid number");
goto main;
}
}
printf("enter the size of 2nd set\n");
scanf("%d",&n);
printf("enter the zeros and ones based on condition\n");
for(int i=0;i<n;i++){
main2:
scanf("%d",&p);
if (p==0 || p==1){
b[i]=p;
}
else{
printf("set only accept 0's and 1's please enter a valid number");
goto main2;
}
}
while(1){
int x;
printf("\n---------------------SET MENU-----------------------\n");
printf("1. Union\n 2. Intersection\n 3. Difference\n 0. exit\n enter the option below\n");
scanf("%d",&x);
switch(x){
case 1: if(m==n)
set_union(a,b,m);
else
printf("union perform only same size of array\n");
exit(1);
break;
case 2: if(m==n)
set_intersection(a,b,m);
else
printf("intersection perform only same size of array\n");
exit(1);
break;
case 3: if(m==n)
set_difference(a,b,m);
else
printf("difference perform only same size of array\n");
exit(1);
break;
case 0:exit(1);
default: printf("invalid option\n");
}
}
}