Table of Contents
C program to check if a number is even or odd
In programming it is easy to find if number is even or odd.
we need to divide it by 2 and if the reminder 0 then it’s even else it’s odd
In C programming we have two methods:
- With IF-ELSE
- With ternary operator
Logic to check if a number is even or odd in C
With IF-ELSE
#include<stdio.h>
//itvoyagers.in
int main()
{
int x;
printf("Enter any number : ");
scanf("%d",&x);
if(x % 2 == 0)
{
printf("n %d is Even",x);
}
else
{
printf("n %d is Odd",x);
}
return 0;
}
Output :
Enter any number : -9
-9 is Odd
Enter any number : 8
8 is Odd
With Ternary operator
#include<stdio.h> //itvoyagers.in int main() { int x; printf("Enter any number : "); scanf("%d",&x); (x % 2 == 0)? printf("n %d is Even",x) : printf("n %d is Odd",x); return 0; }
Output :
Enter any number : 7
7 is Odd
Enter any number : 8
8 is Odd
PRACTICALS/PRACTICE PROGRAM IN C
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
We are aiming to explain all concepts of C in easiest terms as possible.

ITVoyagers
Author