C Program to check Whether a number is Even or Odd

C Program to Check Whether a Number is Even or Odd

In this example, we will learn to check whether a number entered by the user is even or odd.

Remainder :

To understand this example, we should have the knowledge of the following C programming topics:

What are even and odd numbers?

An even number is an integer which is divisible by 2. For example : 0, 2, 4, 6, 8.....etc.

An odd number is an integer which is not divisible by 2. For example: 1, 3, 5, 7, 9....etc.

Program to Check Even or Odd

#include <stdio.h>

int main() {
  int num;
  printf("Enter a number : ");
  scanf("%d", &num);
  if(num % 2 == 0) {
    printf("%d is a even number", num);
  else {
    printf("%d is a odd number", num);
  return 0;


Enter a number : 12
12 is a even number

Working of the above program

  • First we declare a integer variable num.
  • int num;
  • Then we asked the user to enter a number.
  • printf("Enter a number : ");
  • Then we take the user input using scanf() function and store the entered value in num variable.
  • scanf("%d", &num);
  • Finally, we use if...else statement in which if statement has a condition to check num % 2 == 0 i.e. on dividing num by 2 we get 0 as remainder or not (completely divisible by 2 or not).
  • if(num % 2 == 0) {
      printf("%d is a even number", num);
    else {
      printf("%d is a odd number", num);

- Related Topics