27.2.08

Even/Odd number

This is also one of the C Interview questions.

How to tell the given number is even or odd number in single line C code.

Code snippet:
int num;
num&1 ? printf("Odd Number\n") : printf("Even number\n");

Logic is every odd number will have least significant bit has 1
in binary representation of the number.

So when we do bitwise AND with number 1, obviously the
result is '1' for odd numbers and '0' for even numbers.