From 300eca70a86ae47cf421c9c83d0e1069452f2509 Mon Sep 17 00:00:00 2001 From: NovaGod <73330194+NovaGod@users.noreply.github.com> Date: Fri, 23 Oct 2020 12:14:29 +0530 Subject: [PATCH] EVEN or ODD We can check whether an integer number is EVEN or ODD without using any Arithmetic or Relational operators. Here is a simple trick that we can use to check whether number is EVEN or ODD. Using Logical AND (&) operator we can check it, each EVEN number has 0th bit LOW (0) and ODD number has 0th bit HIGH (1). The statement (number & 0x01) will check that 0th bit is HIGH, if it is HIGH (1) number will be an ODD otherwise number will be an EVEN. --- EVEN or ODD | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 EVEN or ODD diff --git a/EVEN or ODD b/EVEN or ODD new file mode 100644 index 00000000..9ee48036 --- /dev/null +++ b/EVEN or ODD @@ -0,0 +1,16 @@ +#include + +int main() +{ + int number; + + //input an integer number + printf("Please input an integer number: "); + scanf("%d",&number); + + //check 0th bit of number is 1 or 0 + (number & 0x01) ? printf("%d is an ODD Number.", number) : printf("%d is an EVEN Number.",number) ; + + printf("\n"); + return 0; +}