Home >>c programs >c program to check odd or even

c program to check odd or even

Check Given number is even number or odd number

Even numbers are those numbers which are perfectly divisible by 2 else it is an odd number.

There are two ways to check whether the input number is even or odd:

  1. using modulus operator (%) by dividing number by 2 and,
  2. using Bitwise Operator

Let's take an example :

#include <stdio.h>
int main()
{
    int num=11;
    if(num%2==0)
    {
    printf("Given Number is eveno num %d",num);    
    }
    else
    {
    printf("Given Number is odd num %d",num);    
    }    
    }
Output :Given Number is odd num

Get input from keyword and check number is even or odd number

A user inputs a number, and we check whether it’s a even or odd. when the input number is completely divisible by 2 then it's an even number otherwise its an odd number.

Let's take an example :

#include <stdio.h>    
int main()
{    
int num=0;    
printf("enter Your  number:");  
//get input and store in num variable
scanf("%d",&num); 
if(num%2==0)
{
printf("Given Number is even num");    
}
else
{
    printf("Given Number is odd num");
}
return 0;  
}    
Output :
enter Your number:10
Given Number is even num
Output :
enter Your number:11
Given Number is odd num