Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Bitwise Algorithms
  • MCQs on Bitwise Algorithms
  • Tutorial on Biwise Algorithms
  • Binary Representation
  • Bitwise Operators
  • Bit Swapping
  • Bit Manipulation
  • Count Set bits
  • Setting a Bit
  • Clear a Bit
  • Toggling a Bit
  • Left & Right Shift
  • Gray Code
  • Checking Power of 2
  • Important Tactics
  • Bit Manipulation for CP
  • Fast Exponentiation
Open In App
Next Article:
C Program to Check if count of divisors is even or odd
Next article icon

C Program to Check for Odd or Even Number

Last Updated : 18 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Write a C program to check whether the given number is an odd number or an even number.

A number that is completely divisible by 2 is an even number and a number that is not completely divisible by 2 leaving a non-zero remainder is an odd number.

Example

Input: N = 4
Output: Even
Explanation: 4 is divisible by 2 with no remainder, so it is an even number.

Input: N = 7
Output: Odd
Explanation: 7 is not completely divisible by 2 leaving 1 as remainder, so it is an odd number.


How to Check Odd or Even Number in C?

In C, there are three different methods which we can use to check if the given number is an odd number or an even number:

Table of Content

  • Check Odd or Even Number Using Modulo Operator
  • Check Odd or Even Number Using Bitwise AND Operator
  • Check Odd or Even Number Using Shift Operator

1. Check Odd or Even Number Using Modulo Operator

The simplest way to check whether the given number is even or odd is to check for the remainder when the number is divided by 2. In C, the remainder of a number divided by another number is given by the modulus operator (%).

C Program to Check Whether the Given Number is Even or Odd

C
// C Program to Check Even or Odd Using Modulo Operator #include <stdio.h>  void checkOddEven(int N) {        // Find the remainder     int r = N % 2;      // Condition for even     if (r == 0)  {         printf("Even");     }        // Condition for odd number     else  {         printf("Odd");     } }  int main() {     int N = 101;     checkOddEven(N);     return 0; } 

Output
Odd

Time Complexity: O(1)
Auxiliary Space: O(1)

2. Check Odd or Even Number Using Bitwise AND Operator

In odd numbers’ binary representation, the least significant bit (LSB) of the number is always set i.e. always 1 while for even numbers, it is always unset i.e. 0. We can use this property to extract the LSB using the bitwise AND operator (&) to check the least significant bit (LSB) of the number.

Below are the steps to implement the above approach:

  • Use the bitwise AND operator on the given number with mask = 1 to extract the LSB of the number.
  • If the result is 0, the given number is even.
  • If the result is 1, the given number is odd.

C Program to Check for Even or Odd Number Using Bitwise AND Operator

C
// C Program to Check Even or Odd Using Bitwise // AND Operator #include <stdio.h>  void checkEvenOdd(int N) {        // Check if the number is even or odd using bitwise   	// AND operator     if (N & 1) {         printf("Odd\n");     }     else {         printf("Even\n");     } }  int main() {     int N = 7;   	checkEvenOdd(N);     return 0; } 

Output
Odd 

Time Complexity: O(1)
Auxiliary Space: O(1)

3. Check Odd or Even Number Using Shift Operator

The LSB in the odd number is always set i.e. 1. So, if we right shift the number by one and then left shift it by one again, then the LSB will become 0 making it unequal to the original number. While, if we do that to even number, it won’t change because the LSB is already 0 from the start.

C Program to Check for Odd or Even Number Using Shift Operator

C
// C Program to Check Even or Odd Using Bitwise AND Operator #include <stdio.h>  void checkEvenOdd(int num) {     int temp = num;     temp = temp >> 1;     temp = temp << 1;      // Check if the number is even or odd using bitwise AND operator     if (temp == num) {         printf("Even\n");     }     else {         printf("Odd\n");     } }  int main() {     int num = 7;     checkEvenOdd(num);     return 0; } 

Output
Odd 

Time Complexity: O(1)
Auxiliary Space: O(1)

Conclusion

Checking whether a number is even or odd can be efficiently implemented using various methods such as the modulo operator, bitwise AND operator, and shift operators. All methods have constant time and space complexity, making them suitable for quick and efficient checks.



Next Article
C Program to Check if count of divisors is even or odd

C

codingbeast12
Improve
Article Tags :
  • Bit Magic
  • C Language
  • C Programs
  • DSA
  • Mathematical
  • Bit Manipulation in C
  • C Basic Programs
  • Natural Numbers
  • Number Divisibility
Practice Tags :
  • Bit Magic
  • Mathematical

Similar Reads

  • Lex program to check whether input number is odd or even
    Lex is a computer program that generates lexical analyzers. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. The commands for executing the lex program are: lex abc.l (abc is the file name) gcc lex.yy.c -ll ./a.ou
    1 min read
  • C Program to Check if count of divisors is even or odd
    Given a number "n", find its total number of divisors is even or odd. Examples : Input : n = 10 Output : Even Input: n = 100 Output: Odd Input: n = 125 Output: Even A naive approach would be to find all the divisors and then see if the total number of divisors is even or odd. C/C++ Code // Naive Sol
    2 min read
  • C/C++ Program for Odd-Even Sort / Brick Sort
    This is basically a variation of bubble-sort. This algorithm is divided into two phases- Odd and Even Phase. The algorithm runs until the array elements are sorted and in each iteration two phases occurs- Odd and Even Phases. In the odd phase, we perform a bubble sort on odd indexed elements and in
    2 min read
  • C Program For Char to Int Conversion
    Write a C program to convert the given numeric character to integer. Example: Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3. Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9. Different Methods to Convert the char to int in CThere are 3
    3 min read
  • C Program to Check Whether a Number is Positive or Negative or Zero
    Write a C program to check whether a given number is positive, negative, or zero. Examples Input: 10Output: PositiveExplanation: Since 10 is greater than 0, it is positive. Input: -5Output: NegativeExplanation: Since -5 is less than 0, it is negative. Different Ways to Check for Positive Numbers, Ne
    3 min read
  • C/C++ Program to Find the Number Occurring Odd Number of Times
    Given an array arr[] consisting of positive integers that occur even number of times, except one number, which occurs odd number of times. The task is to find this odd number of times occurring number. Examples : Input : arr = {1, 2, 3, 2, 3, 1, 3} Output : 3 Input : arr = {5, 7, 2, 7, 5, 2, 5} Outp
    4 min read
  • Palindrome Number Program in C
    Write a C program to check whether a given number is a palindrome or not. Palindrome numbers are those numbers which after reversing the digits equals the original number. Examples Input: 121Output: YesExplanation: The number 121 remains the same when its digits are reversed. Input: 123Output: NoExp
    4 min read
  • C program to print odd line contents of a File followed by even line content
    Pre-requisite: Basics of File Handling in C Given a text file in a directory, the task is to print all the odd line content of the file first then print all the even line content. Examples: Input: file1.txt: Welcome to GeeksforGeeks Output: Odd line contents: Welcome GeeksforGeeks Even line contents
    2 min read
  • C Program For Segregating Even And Odd Nodes In A Linked List
    Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list. Also, keep the order of even and odd numbers the same. Examples: Input: 17->15->8->12->10->5->4->1->7->6-
    4 min read
  • C Program for Difference between sums of odd and even digits
    Write a C program for a given long integer, the task is to find if the difference between sum of odd digits and sum of even digits is 0 or not. The indexes start from zero (0 index is for leftmost digit). Examples: Input : 1212112Output : YesExplanation:the odd position element is 2+2+1=5the even po
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences