Assume that x is already defined as being of type char Writ
Assume that x is already defined as being of type char . Write a single expression that will return true if x is odd. [Note that this compiler doesn\'t accept binary constants , so use hexidecimal instead. I.e., for 0b00111111 use 0x3F.]
Solution
#include <stdio.h> /* printf */
#include <stdlib.h> /* strtol */
int main ()
{
char hex[] = \"0x1A\"; // hexadecimal number equivalent to 26
strtol (hex,NULL,0) & 1 ? printf(\"ODD\"):printf(\"EVEN\"); // strtol converts hexadecimal to decimal & binary operator checks it it\'s odd or not.
return 0;
}
/*
sampleoutput
ODD
*/
