What are Even numbers?

A number which is evenly divisible by 2 is called an even number. It means when you will divide even number by 2 then the remainders will be zero.

For example, 2, 4, 6, ..etc

 

What are the Odd numbers?

If a number that is not evenly divisible by 2 is called an odd number.

 

C program to find even and odd numbers

 

1. Using the if-else condition:

 

#include <stdio.h>
int main()
{
int data;
//Get input from the user
printf(“\n Enter any number: = “);
scanf(“%d”, &data);
//If number is divisible by 2 then
//it is a even number
if((data % 2) == 0)
{
printf(“\n Number is Even.\n\n”);
}
else
{
printf(“\n Number is Odd.\n\n”);
}
return 0;
}

Output 1:

 

Output 2:

 

 

2. Using the ternary condition:

 

#include <stdio.h>
int main()
{
int number;
//Get input from the user
printf(“\n Enter any number: = “);
scanf(“%d”, &number);
//If number is divisible by 2 then
//it is a even number
(number%2) == 0 ? printf(” Even Number \n “) : printf(” Odd Number \n”);
return 0;
}

 

 

3. Using the bit-wise operators:

We can also check even-odd numbers by checking LSB bit. If the LSB bit of a number is set that means odd number otherwise even.

#include <stdio.h>
int main(void)
{
int number;
//Get input from the user
printf(“Enter any number: = “);
scanf(“%d”, &number);
//Check LSB bit of the number
(number&1) ? printf(“Odd Number \n “) : printf(“Even Number \n”);
return 0;
}