Skip to content
Home » C program to check odd or even using bitwise operator

C program to check odd or even using bitwise operator

Learn about C program to check odd or even using bitwise operator in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to check odd or even using bitwise operator

The goal is to determine whether or not the last part of the number is set. If the last bit is set, the number is odd; otherwise, it is even.
As we know, the bitwise AND operation of a number by one will result in a 1 if the last bit is already set. Otherwise, it will provide a value of 0 as output.

Source code:

 #include<stdio.h>
 int main()
 {
     int number;
     printf("Enter number: ");
     scanf("%d",&number);

     if(number&1) printf("Odd");
     else printf("Even");

     return 0;
 }

Output:

Enter number: 7
Odd

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Even or odd program without using modulus operator in C
Even Odd Program in C using function