Sunday, July 09, 2006

To check whether the number is Even or Odd using if else

This Program checks whether the entered number is even or odd...


Any integer is input through the keyboard.

Write a program to find out whether it is an odd number or even number.



#include<stdio.h>
main()
{

int num;

printf ("Enter a number to be checked for even/odd: ");
scanf ("%d",&num);

if (num%2==0)
{
printf ("The entered number is EVEN.\n");

}
else
{
printf ("The entered number is ODD.\n");

}
}



The file can also be downloaded at:
Download File



10 comments:

Arijit said...

#include
#include
void main()
{
int i;
clrscr();

printf("\n Input any number");
scanf("%d",&i);

if(i%2==0);
{
printf("\n Number is even");
}
else
{
printf("\n Number is odd");
}
getch();
}

Mithelash said...

#include
main()
{
int n;
printf ("Enter a number: ");
scanf ("%d",&n);
(n%2==0 ? printf("Even no"):printf ("ODD no"));
}
we can do this by using condition operator

van0014 said...
This comment has been removed by the author.
van0014 said...

there is an easier method. as long as your compiler can check if a number has a decimal or not. For example, my compiler has a check called frac() which returns either true of false if a decimal value is present.

frac([number]/2)

that will return either 1 or 0 if the number is even or odd

Anonymous said...

realy helpful thnxx arjit

Anonymous said...

as u say bt when we divided 6/2=3 which is not equal to 0,,then it means 6 is not an even number...??

Anonymous said...

With out using if-else...write a program to check whether the number is even or odd.

Anonymous said...

why % sign is used here in if statement i.e if(num%2==0)

sanjay varma said...

Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

Anonymous said...

u dont no anything motherf**ker