# include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct SetABC
{
unsigned int st;
} SetABC;
void PrintSet(SetABC st);//seif 1
SetABC UnionABC(SetABC st1, SetABC st2);//seif 2
SetABC IntersectABC(SetABC st1, SetABC st2);//seif 3
SetABC MinusABC(SetABC st1, SetABC st2);//seif 4
void main()
{
int num = 0, i = 0, second, third, fourth;
SetABC st1, st2, sec, three, four;
char buffer[27], buffer2[27];
printf("Enter the first number: ");
scanf("%d", &(st1.st));
printf("Enter the second number: ");
scanf("%d", &(st2.st));
printf("\nThe letters that belongs to original numbers are:\n");
PrintSet(st1);
PrintSet(st2);
sec = UnionABC(st1, st2);//seif 2
printf("(%d) ", sec.st);
PrintSet(sec);
three = IntersectABC(st1, st2);//seif 3
printf("(%d) ", three.st);
PrintSet(three);
four = MinusABC(st1, st2);//seif 4
printf("(%d) ", four.st);
PrintSet(four);
getch();
}
void PrintSet(SetABC st)//seif 1
{
char ABC = 'a', buffer[27];
int i = 0, k;
unsigned int *p = &(st), t, num;
num = *p;
itoa(num, buffer, 2);
i = strlen(buffer);
if (i > 26)
printf("The length of binary number too long for use the english ABC");//errore message
else
{
k = i;
while (k > 0)//while the place in the range of ABC
{
if (buffer[k - 1] & 1 == 1)//if the number is 1 so the bit works we shoud print the correct letter
printf("%c", ABC + i - k);
k--;//next place on the buffer
}
printf("\n");
}
}
SetABC UnionABC(SetABC st1, SetABC st2)//seif 2
{
struct SetABC sec;
sec.st = st1.st | st2.st;
printf("\nOR:\n");
return sec;
}
SetABC IntersectABC(SetABC st1, SetABC st2)//seif 3
{
struct SetABC three;
three.st = st1.st & st2.st;
printf("\nAND:\n");
return three;
}
SetABC MinusABC(SetABC st1, SetABC st2)//seif 4
{
struct SetABC four;
four.st = st1.st ^ st2.st;
printf("\nXOR:\n");
return four;
}
Copyright©1996-2021,Tapuz Media Ltd. Forum software by XenForo® © 2010-2020 XenForo Ltd.