Write a C program to check whether a number is even or odd using if else. How to check whether a number is even or odd using if else in C program. Program to input any number from user and check whether the given number is even or odd.

Input number: 10

Output: 10 is even number

Here in this program we only need to perform modular division. A number is even if num % 2 == 0 otherwise it is odd.

Happy coding ;)

**Example:**Input number: 10

Output: 10 is even number

### Required knowledge

Basic C programming, Arithmetic operator, If else### Logic to check even or odd

We know, if a number is clearly divisible by 2 then the number is even otherwise odd. Hence logic of the program is clear and simple, we only need to check whether the number is divisible by 2 or not. We have also seen in one of previous post how to check divisibility of any number by performing modular division.Here in this program we only need to perform modular division. A number is even if num % 2 == 0 otherwise it is odd.

### Program to check even or odd

/** * C program to check even or odd number */ #include <stdio.h> int main() { int num; /* Reads number from user */ printf("Enter any number to check even or odd: "); scanf("%d", &num); /* Check if the number is divisible by 2 then it is even */ if(num%2 == 0) { printf("Number is Even.\n"); } else { printf("Number is Odd.\n"); } return 0; }

Advance your programming skills by learning this program using other methods :

C program to check even or odd using switch case.

C program to check even or odd using conditional operator.

C program to check even or odd using functions.

C program to check even or odd using bitwise operator.

C program to check even or odd using switch case.

C program to check even or odd using conditional operator.

C program to check even or odd using functions.

C program to check even or odd using bitwise operator.

Output

Enter any number to check even or odd: 11

Number is Odd

Number is Odd

Happy coding ;)

### You may also like

- If else programming exercises index.
- C program to print all even numbers between 1 to n.
- C program to print sum of all odd numbers between 1 to n.
- C program to find sum of even or odd numbers using recursion.
- C program to enter two numbers and find maximum between two.
- C program to enter month number and print total number of days in that month.
- C program to print week day name.
- C program to check leap year.
- C program to find power of any number x^y.
- C program to find total, average and percentage of marks of five subjects.

Very nice. know details

ReplyDeleteVisit nice example Even odd logic

ReplyDeleteVery Nice Post visit nice example also Even odd example in java

ReplyDelete