Previews Example View All C Programs Next Example

# Program to Check Whether a Number is Even or Odd in C

Numbers perfectly divisible by 2 are known even numbers and numbers which are not divisible by 2 are called odd numbers. This program takes an integer from user and checks whether that number is even or odd and displays the result.

#include <stdio.h> #include <conio.h> main(){ int n; printf("Enter an integer you want to check: "); scanf("%d",&n); if((n%2)==0) /* Checking whether remainder is 0 or not. */ printf("%d is even.",n); else printf("%d is odd.",n); getch(); }

##### Result

Enter an integer you want to check: 5

5 is odd.

Enter an integer you want to check: 10

10 is even.

5 is odd.

Enter an integer you want to check: 10

10 is even.

In this program, user is asked to enter an integer which is stored in variable n. Then, the remainder is found when that number is divided by 2 and checked whether remainder is 0 or not. If remainder is 0 then, that number is even otherwise that number is odd. This task is performed using if...else statement in C programming and the result is displayed.