Thursday, 21 August 2014

Filled Under: ,

C Program to Check any Number is Even or Odd

Share

The number which is perfectly divisible by 2 is called even number and the number which is not divisible by 2 is called odd number.On the basis of above concept we provide a C Program to check any number is even or odd.This program takes any integer number and and after execution it will tells that number is even or odd.It is very simple c program to check any number is even or odd.We hope it will help you to understand the basic logic and syntax of c programming.

C Program to Check any Number is Even or Odd

#include<stdio.h>
int main()
{
 int a;
 printf("n Enter a number : ");
 scanf("%d",&a);
 if(a%2==0)
  printf("Number is even");
else
 printf("Number is odd");
return 0;
}
Output 1
Enter a number : 17
Number is odd
Output 2
Enter a number : 34
Number is even.
Explanation
In this program, user is asked to enter an integer which is stored in variable a. 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 accordingly.