Wednesday, 25 March 2015

C Program to check whether a number is even or odd


 

In this program we make use of the logic that an even number is always divisible by 2.Which means on diving a number by 2 the remainder must be zero.



#include<stdio.h>
#include<conio.h>
void  main()
{

int a;
clrscr();
printf("Enter a number");
scanf("%d",&a);

if(a%2==0)  // comparing the remainder with 0
   printf("EVEN NUMBER");
else 
   printf("ODD NUMBER");

getch();


}


Output:


0 comments:

Post a Comment