Code:
#include <stdio.h>
int xor (int x, int y);
int main(void)
{
int a;
int x;
int y;
int b;
int c;
int d;
int e;
int f;
int g;
printf ("How many addresses would you like to XOR? ");
scanf ("%d", &a);
getchar();
while (a < 2 || a > 8)
{
printf ("Invalid entry please try again: ");
scanf ("%d", &a);
getchar();
}
if (a==2)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("The XOR value of the 2 numbers is: %x\n" ,xor (x,y));
getchar();
return 0;
}
else if (a==3)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("Please enter the third number you'd like to XOR: ");
scanf ("%x", &b);
printf ("The XOR value of the 3 numbers is: %x\n" ,xor1 (x,y,b));
getchar();
return 0;
}
else if (a==4)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("Please enter the third number you'd like to XOR: ");
scanf ("%x", &b);
printf ("Please enter the forth number you'd like to XOR: ");
scanf ("%x", &c);
printf ("The XOR value of the 4 numbers is: %x\n" ,xor2 (x,y,b,c));
getchar();
return 0;
}
else if (a==5)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("Please enter the third number you'd like to XOR: ");
scanf ("%x", &b);
printf ("Please enter the forth number you'd like to XOR: ");
scanf ("%x", &c);
printf ("Please enter the fifth number you'd like to XOR: ");
scanf ("%x", &d);
printf ("The XOR value of the 5 numbers is: %x\n" ,xor3 (x,y,b,c,d));
getchar();
return 0;
}
else if (a==6)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("Please enter the third number you'd like to XOR: ");
scanf ("%x", &b);
printf ("Please enter the forth number you'd like to XOR: ");
scanf ("%x", &c);
printf ("Please enter the fifth number you'd like to XOR: ");
scanf ("%x", &d);
printf ("Please enter the sixth number you'd like to XOR: ");
scanf ("%x", &e);
printf ("The XOR value of the 6 numbers is: %x\n" ,xor4 (x,y,b,c,d,e));
getchar();
return 0;
}
else if (a==7)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("Please enter the third number you'd like to XOR: ");
scanf ("%x", &b);
printf ("Please enter the forth number you'd like to XOR: ");
scanf ("%x", &c);
printf ("Please enter the fifth number you'd like to XOR: ");
scanf ("%x", &d);
printf ("Please enter the sixth number you'd like to XOR: ");
scanf ("%x", &e);
printf ("Please enter the seventh number you'd like to XOR: ");
scanf ("%x", &f);
printf ("The XOR value of the 7 numbers is: %x\n" ,xor5 (x,y,b,c,d,e,f));
getchar();
return 0;
}
else if (a==8)
{
printf ("Please enter the first number you'd like to XOR: ");
scanf ("%x", &x);
printf ("Please enter the second number you'd like to XOR: ");
scanf ("%x", &y);
printf ("Please enter the third number you'd like to XOR: ");
scanf ("%x", &b);
printf ("Please enter the forth number you'd like to XOR: ");
scanf ("%x", &c);
printf ("Please enter the fifth number you'd like to XOR: ");
scanf ("%x", &d);
printf ("Please enter the sixth number you'd like to XOR: ");
scanf ("%x", &e);
printf ("Please enter the seventh number you'd like to XOR: ");
scanf ("%x", &f);
printf ("Please enter the eighth number you'd like to XOR: ");
scanf ("%x", &g);
printf ("The XOR value of the 8 numbers is: %x\n" ,xor6 (x,y,b,c,d,e,f,g));
getchar();
return 0;
}
}
int xor (int x, int y)
{
return x ^ y;
}
int xor1 (int x, int y, int b)
{
return x ^ y ^ b;
}
int xor2 (int x, int y, int b, int c)
{
return x ^ y ^ b ^ c;
}
int xor3 (int x, int y, int b, int c, int d)
{
return x ^ y ^ b ^ c ^ d ;
}
int xor4 (int x, int y, int b, int c, int d, int e)
{
return x ^ y ^ b ^ c ^ d ^ e ;
}
int xor5 (int x, int y, int b, int c, int d, int e, int f)
{
return x ^ y ^ b ^ c ^ d ^ e ^ f;
}
int xor6 (int x, int y, int b, int c, int d, int e, int f, int g)
{
return x ^ y ^ b ^ c ^ d ^ e ^ f ^ g;
}
I'd like to say this is not a homework assignment, I've been following the tutorials on this site and writing some samples for practice. Any tips would be appreciated.