How to tell the given number is even or odd number in single line C code.
Code snippet:
int num;Logic is every odd number will have least significant bit has 1
num&1 ? printf("Odd Number\n") : printf("Even number\n");
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.