Write a program to check a number is even or odd in C

Checking a user-entered number is even or odd is so easy only If, you know conditional statements in C.So Let’s understand odd or even program in C.

odd or even number in C

If you don’t know about conditional statements So let me brief you.

Conditional Statements

Conditional statements are a formula that helps us to compare two variables or object values.

In this program, we learn only if…else conditional statement.

If…else syntax

If(condition expression)
{
statements...
statements...
}
else
{
statements...
statements...
}

How if…else works

Else is the optional statement. If condition expression true, first module of statements will execute otherwise else statements will be executed automatically.

Ok! Let’s start

Odd or even program in C

#include<stdio.h>
#include<conio.h>

void main()
{
int n;
clrscr();
printf("Enter any number to check it for even or odd");
scanf("%d",&n);
//Checking a number for even or odd
if(n%2==0)
{
printf("It is an even number");
}
else
{
printf("It is an odd number");
}
getch();
}

Program Code Explanation(PCE)

As earlier said, this program requires conditional statement if…else. So I used this conditional statement. I use modulo operator(%) to find reminder if we divided a user-entered number by 2. If the result is zero so it is an even number otherwise it is an odd number.

You may also search for

Hope that you understand the above code. And you learn odd or even program in c. Don’t worry, if you have any queries or questions please don’t forget to ask in below comment section.

Also if you like please share this to your friends or social media family.

If you like travelling follow our other blog travelthenature.com

Leave a Comment

Show Buttons
Hide Buttons