C Program to Find Whether the Number is Even or Odd


We all know, the number which can divide from 2 completely, means if the reminder is zero, then the number is even and which cannot are odd numbers.

The same we will do in our program to know whether the number, which is input through the keyboard, is even or odd.

Remember the modulus operator (%), this operator returns the reminder, when dividing any number. So we will condition the if statement, if the reminder is zero after diving the number by 2, then the number is even otherwise odd.

Let’s have ah Look The Program ►►

#include<stdio.h>
#include<conio.h>
 
void main()
{
   int num;
   printf("Enter Number to know it's even or odd");
   scanf("%d",&num);

   if(num%2==0)
   printf("%d is Even",num);

   else
   printf("%d is Odd",num);
 
   getch();   
}

I think you already understand the program. I simply used the modulus operator (%) and condition if(num%2==0), means after dividing the number by 2, if the reminder is zero then number is even, else the number is odd.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s