Check even and odd in cpp is c++ program to check whether number is even or odd.
In this tutorial, we are looking new program which is to find an even or odd number.
In this program, we first have a number and we check whether that number is Even or odd programmatically.
Definition of odd and even numbers
What is even number
Any number which is divided by 2 and gives the remainder zero is Even number.
What is odd number
Any number which is divided by 2 but gives reminder 1 is an odd number.
To check whether a number is even or odd we need some basic mathematical formula.
The mathematical formula to find out whether a number is even or odd is as follows
Result = Number % 2
In above formula, The number is any number of which we are checking even or odd number.
If this number gives the reminder 0 then it’s even number else number is odd.
Example
Number = 10
Reminder = Number % 2
Reminder = 0
So, Number is even
Number = 5
Reminder = Number % 2
Reminder = 1
So, Number is odd.
In this way, we check whether Number is even or odd.
Using this way we implement the program to find even or odd in cpp.
Write a program to check whether the given number is even or odd in c++
123456789101112131415161718192021222324252627282930313233343536 | #include <iostream>using namespace std;int main(){int number;cout<<“Enter a Number \n”;cin>>number; if(number % 2 == 0) { cout<<“The number “<< number<<” is Even”; }else { cout<<“The number “<< number<<“is Odd”; } cout<<“\n”;} |
Output

Explanation
1. First, Here we declared an integer number.
2. Then we took the input from a user using cin statement.
3. As we know modulus operator is used to return the remainder of two values as (10%3=1, 12%2=0).
4. So if you do modulus with 2 then the remainder would be ‘zero’ for Even numbers and ‘1’ for Odd numbers.
5. If we divide ‘number’ with ‘2’ using mod operator then depending upon condition the respective cout will be executed.
6. In above output, 5 % 2 = 1 so The number is odd will be printed.