# include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct SetABC
{
unsigned int st;
} SetABC;
void PrintSet(SetABC st);//seif 1
SetABCUnionABC(SetABC st1, SetABC st2);//seif 2
SetABCIntersectABC(SetABC st1, SetABC st2);//seif 3
SetABCMinusABC(SetABC st1, SetABC st2);//seif 4
void main()
{
int num = 0, i = 0, second, third, fourth;
SetABC st1, st2;
char buffer[27], buffer2[27];
printf("Enter the first number: ");
scanf("%d", &(st1.st));
printf("Enter the second number: ");
scanf("%d", &(st2.st));
itoa(st1.st, buffer, 2);//transmite to binary number
itoa(st2.st, buffer2, 2);
printf("\nThe letters that belongs to original numbers are:\n");
PrintSet(st1);
PrintSet(st2);
second = SetABCUnionABC(st1, st2);//seif 2
printf("(%d)\n", second);
third = SetABCIntersectABC(st1, st2);//seif 3
printf("(%d)\n", third);
fourth = SetABCMinusABC(st1, st2);//seif 4
printf("(%d)\n", fourth);
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");
}
}
SetABCUnionABC(SetABC st1, SetABC st2)//seif 2
{
char buffer[27];
unsigned int c = 0, *a = &st1, *b = &st2, t;
c = *a | *b;
printf("\nOR:\n");
itoa(c, buffer, 2);
t = atoi(buffer);
return t;
}
SetABCIntersectABC(SetABC st1, SetABC st2)//seif 3
{
char buffer[27];
unsigned int c = 0, *a = &st1, *b = &st2, t;
c = *a & *b;
printf("\nAND:\n");
itoa(c, buffer, 2);
t = atoi(buffer);
return t;
}
SetABCMinusABC(SetABC st1, SetABC st2)//seif 4
{
char buffer[27];
unsigned int c = 0, *a = &st1, *b = &st2, t;
c = *a ^ *b;
printf("\nXOR:\n");
itoa(c, buffer, 2);
t = atoi(buffer);
return t;
}