C Online Compiler
Example: Check Even or Odd Using Bitwise AND in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Check Even or Odd Using Bitwise AND #include <stdio.h> int main() { int num; // Step 1: Prompt the user to enter a number printf("Enter an integer: "); // Step 2: Read the integer input from the user scanf("%d", &num); // Step 3: Check if the number is even or odd using the bitwise AND operator // If the LSB is 0, num & 1 will be 0 (even) // If the LSB is 1, num & 1 will be 1 (odd) if ((num & 1) == 0) { printf("%d is an even number.\n", num); } else { printf("%d is an odd number.\n", num); } return 0; }
Output
Clear
ADVERTISEMENTS