- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ Program to Check Whether Number is Even or Odd

A number is even if it is divisible by two and odd if it is not divisible by two.

Some of the even numbers are −

2, 4, 6, 8, 10, 12, 14, 16

Some of the odd numbers are −

1, 3, 5, 7, 9, 11, 13, 15, 17

## Check Whether Number is Even or Odd using Modulus

A program to check whether number is even or odd using modulus is as follows.

## Example

#include <iostream> using namespace std; int main() { int num = 25; if(num % 2 == 0) cout<<num<<" is even"; else cout<<num<<" is odd"; return 0; }

## Output

25 is odd

In the above program, the number num is divided by 2 and its remainder is observed. If the remainder is 0, then the number is even. If the remainder is 1, then the number is odd.

if(num % 2 == 0) cout<<num<<" is even"; else cout<<num<<" is odd";

## Check Whether Number is Even or Odd Using Bitwise AND

A number is odd if it has 1 as its rightmost bit in bitwise representation. It is even if it has 0 as its rightmost bit in bitwise representation. This can be found by using bitwise AND on the number and 1. If the output obtained is 0, then the number is even and if the output obtained is 1, then the number is odd.

A program to check whether number is even or odd using Bitwise AND is as follows −

## Example

#include <iostream> using namespace std; int main() { int num = 7; if((num & 1) == 0) cout<<num<<" is even"; else cout<<num<<" is odd"; return 0; }

## Output

7 is odd

In the above program, bitwise AND is done on num and 1. If the output is 0, then num is even, otherwise num is odd.

if((num & 1) == 0) cout<<num<<" is even"; else cout<<num<<" is odd";

- Related Articles
- Java Program to Check Whether a Number is Even or Odd
- 8085 program to check whether the given number is even or odd
- Java program to find whether given number is even or odd
- Check whether given floating point number is even or odd in Python
- Python Program to Determine Whether a Given Number is Even or Odd Recursively
- Golang Program to Determine Recursively Whether a Given Number is Even or Odd
- C Program to Check if count of divisors is even or odd?
- C# Program to check if a number is Positive, Negative, Odd, Even, Zero
- PHP program to check if the total number of divisors of a number is even or odd
- How to Check if a Number is Odd or Even using Python?
- Java Program to check if count of divisors is even or odd
- Program to check if a number is Positive, Negative, Odd, Even, Zero?
- Check whether product of 'n' numbers is even or odd in Python
- Check whether the length of given linked list is Even or Odd in Python
- C++ Program to Check Whether a Number is Prime or Not