Written by Sai Sameera Thota on January 26, 2013 in C > Programming

C Program to find a Number is Even or not

GET ALERTS:

Get our Latest updates delivered to your mailbox!

C Program to find given number is Even or not, In this program we are defining a single variable n, which is used to read the input and it is then used to check for the remainder by dividing it with 2. If the remainder is 0 then the number is even else it is odd.

Condition: n%2==0.

C Program to find Number is Even or odd

We are using conditional operators in this program. If you are don’t know about conditional operators then check this out.

#include<stdio.h>
#include<conio.h>
main()
{
      int n;
      printf("Enter any positive integer : ");
      scanf("%d",&n);
      printf("%s",n%2==0 ? "Even Number" : "Odd Number");
      getch();
}

C Program to find a number is Even or Not without using Operators

#include<conio.h>
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("\n Enter any positive integer : ");
scanf("%d",&n);
if (n%2==0)

	printf("\n Even Number");

else

	printf("\n Odd Number");

getch();
}

Output:

even-or-odd

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: