# Wap - Even Odd Program in C

January 16, 2021
• An even number is a number that is exactly divisible by 2 and generates a remainder of 0.
• Example: 2, 4, 6.
• Whereas an odd number is a number that is not exactly divided by 2 and generates a remainder of 1.
• Example: 1, 3, 5.

Program Description: even or Odd program in C using the modulus operator

#include <stdio.h>
int main() {
int number;
printf("Enter an integer number: ");
scanf("%d", &number);
//Check if number is perfectly divisible by 2
if(number % 2 == 0){
printf("Even Number");
}else{
printf("Odd Number");
}
return 0;
}

OUTPUT

Enter an integer number: 6
Even Number

In this program, the user entered a number is stored in the variable number. If the input number is perfectly divisible, then it is even number. Else it is an odd number.

0 0
January 16, 2021

In this program, we have used the ternary operator instead of an if-else condition.

#include
int main() {
int number, check_even;
printf("Enter an integer number: ");
scanf("%d", &number);

check_even=(number % 2 == 0) ? 1 : 0;
if(check_even==1){
printf("Even Number");
}else{
printf("Odd Number");
}
return 0;
}

OUTPUT

Enter an integer number: 8
Even Number
0 0
January 16, 2021

Program Description: C program to find odd or even using a bitwise operator.

#include <stdio.h>
int main()
{
int number;
printf("\nEnter an integer Number:");
scanf("%d", &number);

if (number & 1 == 1){
printf("Odd Number");
}else{
printf("Even Number");
}
return 0;
}

OUTPUT

Enter an integer Number:6
Even Number

0 0
January 16, 2021
#include <stdio.h>
void main()
{
int number, rem;

printf("Enter an integer Number: ");
scanf("%d", &number);
rem = number % 2;
if (rem == 0)
printf("%d is an even number", number);
else
printf("%d is an odd number\n", number);
}

OUTPUT

Enter an integer Number: 5
5 is an odd number

0 0