BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to check if number is even or odd

Last Updated: February 11, 2015 by Chaitanya Singh | Filed Under: C Programs

If a number is exactly divisible by 2 then its an even number else it is an odd number. In this article we have shared two ways(Two C programs) to check whether the input number is even or odd. 1) Using Modulus operator(%) 2) Using Bitwise operator.

Program 1: Using Modulus operator

/* Program to check whether the input integer number 
 * is even or odd using the modulus operator (%)
 */
#include<stdio.h>
int main()
{
   // This variable is to store the input number 
   int num;
 
   printf("Enter an integer: ");
   scanf("%d",&num);
 
   // Modulus (%) returns remainder
   if ( num%2 == 0 )
      printf("%d is an even number", num);
   else
      printf("%d is an odd number", num);
 
   return 0;
}

Output:
checking_even_odd_modulus_cmd

Program 2: Using Bitwise operator

/* Program to check if number is even or odd
 * using bitwise operator
 */
#include<stdio.h>
 
int main()
{
   int n;
 
   printf("Enter an integer: ");
   scanf("%d",&n);
 
   if ( n & 1)
      printf("%d is an odd number", n);
   else
      printf("%d is an even number", n);
 
   return 0;
}

Output:
checking_even_odd_bitwise

Top Related Articles:

  1. C Program to concatenate two strings without using strcat
  2. C Program to validate a given date
  3. C Program to Check whether an Alphabet is Vowel or Consonant
  4. C Program to calculate Area of an Equilateral triangle
  5. C Program to read and print employee details using structure

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap