### Even OR Odd Number

If the given number is divisible by 2 then we called it as even number and remaining ones (not divisible by 2) are called as odd numbers. In this article we will show you, How to write a C Program to Check Odd or Even number using If Statement and Conditional Operator with example

In C language we have an Arithmetic Operator called % (Module) to check the remainder of the division. Let’s use this operator to find the remainder, if the remainder is 0 then the number is even else odd number.

## C Program to Check Odd or Even using IF Condition

This program allows the user to enter integer and checks whether that number is even or odd using If statement.

**CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* C Program to Check Odd or Even using IF Condition */ #include<stdio.h> int main() { int number; printf(" Enter an int value to check Even or Odd \n"); scanf(" %d ", &number); if ( number%2 == 0 ) //Check whether remainder is 0 or not printf("Given number %d is EVEN NUMBER \n", number); else printf("Given number %d is ODD NUMBER \n", number); return 0; } |

**ANALYSIS**

Below printf statement will ask the user to Enter any integer value to check whether it is Even or Odd.

1 |
printf(" Enter an int value to check Even or Odd \n "); |

Any number that is completely divisible 2 is even number. If condition will check whether the remainder of the number divided by 2 is exactly equal to 0 or not.

- If the condition is True then it is Even number
- If the condition is False then it is Odd number

**OUTPUT**

Enter the second value to check for the even number

You can observe from the above code that, we used if condition to check whether the remainder of the given integer is 0 or not and print as per the result.

## C Program to Check Even or Odd using Conditional Operator

We can also use the Conditional operator to check whether the number is even or odd. Lets see the example of this

**CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* C Program to Check Even or Odd Using Conditional Operator */ #include<stdio.h> int main() { int number; printf(" Enter an int value to check Even or Odd \n "); scanf(" %d ",&number); number%2 == 0 ? printf(" Even Number \n ") : printf(" Odd Number \n"); return 0; } |

**OUTPUT**

Thank you for visiting our Blog

## Leave a Reply