-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitstring.c
122 lines (118 loc) · 1.71 KB
/
bitstring.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
113
114
115
116
117
118
119
120
121
#include <stdio.h>
void input();
void output();
void setunion();
void intersection();
void difference();
int a[]={0,0,0,0,0,0,0,0,0},b[]={0,0,0,0,0,0,0,0,0};
int main()
{
int ch,wish;
do
{
printf("\n MENU \n");
printf("1.Input\n2.Union\n3.Intersection\n4.Difference\n");
printf("Enter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:input();
break;
case 2:setunion();
break;
case 3:intersection();
break;
case 4:difference();
break;
}
printf("\nDo you wish to continue ?(1/0)\n"); scanf("%d",&wish);
} while(wish==1);
}
void input()
{
int n,x,i;
printf("enter size of the 1st set:");
scanf("%d",&n);
printf("enter elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&x);
a[x-1]=1;
}
printf("enter size of the 2nd set:");
scanf("%d",&n);
printf("enter elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&x);
b[x-1]=1;
}
printf("\n1st set:\n");
for(i=0;i<8;i++)
{
printf("%d",a[i]);
}
printf("\n2nd set:\n");
for(i=0;i<8;i++)
{
printf("%d",b[i]);
}
}
void output(int c[])
{
int i;
printf("\n Set is :");
for(i=0;i<9;i++)
{
if (c[i]!=0)
printf("%d ",i+1);
}
}
void setunion()
{
int i,c[10];
for(i=0;i<9;i++)
{
if (a[i]!=b[i])
c[i]=1;
else
c[i]=a[i];
}
for(i=0;i<9;i++)
{
printf("%d",c[i]);
}
output(c);
}
void intersection()
{
int i,c[10];
for(i=0;i<9;i++)
{
if (a[i]==b[i])
c[i]=a[i];
else
c[i]=0;
}
for(i=0;i<9;i++)
{
printf("%d",c[i]);
}
output(c);
}
void difference()
{
int i,c[10];
for(i=0;i<9;i++)
{
if (a[i]==1 && b[i]==0)
c[i]=1;
else
c[i]=0;
}
for(i=0;i<9;i++)
{
printf("%d",c[i]);
}
output(c);
}