# C program to check whether the given number is even or odd.

c program to check whether the given number is even or odd.

2 Likes

Program:
#include
int main()
{
int a;
printf(“Enter a:
“);
scanf(”%d”, &a);
/* logic */
if (a % 2 == 0)
{
printf("The given number is EVEN
");
}
else
{
printf("The given number is ODD
");
}
return 0;
}

Output:
Enter a: 2
The given number is EVEN

Example 1: If entered number is an even number
Let value of ‘a’ entered is 4
if(a%2==0) then a is an even number, else odd.
i.e. if(4%2==0) then 4 is an even number, else odd.
To check whether 4 is even or odd, we need to calculate (4%2).
/* % (modulus) implies remainder value. /
/
Therefore if the remainder obtained when 4 is divided by 2 is 0, then 4 is even. */
4%2==0 is true
Thus 4 is an even number.

#include
void main()
{
int a;
printf(“enter a value”);
scanf9"%d",&a);
if(a/2==0)
printf(“the given no’r is even”)
else
printf(the no’r is odd");

#include

main()

{

int r,n;

printf("

Enter a positive number : ");

scanf("%d",&amp;n);

r =n%2;

if(r==0)

printf("

The %d is an even number",n);

else

printf("

The %d is an odd number",n);

}

#include

#include

void main()

{

int a;

clrscr();

printf(“enter the number

”);

scanf(“%d”,&amp;a);

if(a%2==0)

printf(“even number”);

else

printf(“odd number”);

getch();

}

[b]Output: [/b]

enter the number

9

odd number