// test2.c : Algorithm design by Rock on April 1 2009.
// test2.c : First coding edition by Nudtsong on Oct 21 2009. (coding)
// test2.c : First revised edition by Ivanov on Oct 21 2009. (Modified Lemma 5)
// test2.c : Second revised by Ivanov on Oct 21 2009. (Added Lemma 6)
#include "stdio.h"
int main(int argc, char argv[])
{
unsigned int a = 0;
unsigned int b = 0;
unsigned int c1 = 0;
unsigned int c2 = 0;
LABEL_INPUT:
// User inputÈë
printf("Please input two integers: A, B must be odd or even\n");
printf("A=");
scanf("%d", &a);
printf("B=");
scanf("%d", &b);
// Does check A,B one odd and one even number?
if (((0 == (a % 2)) && (0 != (b % 2)))
|| ((0 != (a % 2)) && (0 == (b % 2))))
{
printf("error:A, B must be odd or even numbers\n");
goto LABEL_INPUT;
}
else if ((0 != (a % 2)) && (0 != (b % 2))) // If A,B are odd numbes
{
printf("A, B are odd numbers\n");
c1 = a ^ b;
c2 = (-a) ^ (-b);
printf("C1=%d, C2=%d\n", c1, c2);
}
else // If A, B are even numbers
{
//printf("A, B are even numbers\n");
if ((0 == (a % 4)) && (0 == (b % 4))) {
if ((0 != (a % 8)) && (0 != (b % 8)))
{
// A,B are divisible by 4 rather than 8
printf("A, B be divided 4 and be not divided 8\n");
c1 = a ^ b;
c2 = (-a) ^ (-b);
printf("C1=%d, C2=%d\n", c1, c2);
}
else {
printf("a or b is divisible by 8\n");
goto LABEL_INPUT;
}
}
else {
if ((a % 4) == (b % 4)) {
printf("A,B are even and 4 | abs(A-B) \n");
c1 = a ^ b;
c2 = (-a) ^ (-b);
printf("C1=%d, C2=%d\n", c1, c2);
}
else
{
printf(" A,B are even but A or B or abs(A-B) is not divisible by 4\n");
goto LABEL_INPUT;
}
}
}
system("pause");
goto LABEL_INPUT;
return 0;
}