/* * Project1.c * Chapter 9 * By John Stile * Purpose: A logical operator not found in C is exclusive-or (XOR) * Logic: TRUE if and only if one sub-expression is TRUE * * Write a function xor() that takes two expressions that evaluate to integers, * and returns int 1 if one of the expressions evalutates to true */ #include #include "Project1.h" // xor function: one and only one can be true int xor(int aa, int bb) { if ( (aa>1) || (bb>1) ) // check that they endered valid number { printf("I asked for input of 0 or 1!!!\n"); printf("Result will be unreliable\n"); return 0; } if (aa) // if aa is true, do block { if (bb) // if bb is also true, do block { // both true, return 0 return 0; } else { // one is true, return 1 return 1; } } else { if (bb) // only one is true, return 1 { return 1; } else // both false, return 0 { return 0; } } }