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. Logic to check even/odd in C program.

**Example**

**Input**

Input number: 10

**Output**

10 is even number

## Required knowledge

Basic C programming, Arithmetic operator, If else

## Logic to check even or odd

Mathematically we say, even number is a number which is completely divided by 2 leaving no remainder. Programatically, if any number modulo divided by 2 is equal to 0 then, the number is even otherwise odd.

Below is the step by step descriptive logic to check whether a number is even or odd.

- Input a number from user, store it in some variable say num.
- Check if number modulo division equal to 0 or not. The given number is even if num % 2 == 0.

**Important Note:** Never confuse modulo division % operator as the percentage operator. There is no percentage operator in C.

Let us write program to check even odd.

## Program to check even or odd

```
/**
* C program to check even or odd number
*/
#include <stdio.h>
int main()
{
int num;
/* Input 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)
{
// num % 2 is 0
printf("Number is Even.");
}
else
{
//num % 2 is 1
printf("Number is Odd.");
}
return 0;
}
```

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

Output

Enter any number to check even or odd: 11 Number is Odd

Happy coding 😉

### Recommended posts

- 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 print week day name.
- C program to check leap year.

<pre><code> ----Your Source Code---- </code></pre>