
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Copy Files from One Folder to Another Using Python
We can easily check the Odd or Even by using conditional statements.
- We can divide the number by 2, then check whether the remainder is 0 or not. If 0, then it is even.
- We can also perform the AND operation with the number and 1. If the answer is 0, then it is even; otherwise odd.
There is no need to use conditional statements in both approaches. We will see two different methods to check the odd or even.


Using Modulo Operator
This approach uses the Modulo Operator to determine whether the number is even or odd. We will show you the process to check whether the given number is even or not all you have to do is follow the steps below.
Steps
Following are the steps:/p>
- Take an integer input from the user.
- Declare an array with two values: "Even" and "Odd". We will use the remainder to access the appropriate index in this array.
- Now, print the value at the index corresponding to the remainder. If the number is even, the remainder will be 0, and "Even" will be printed. If the number is odd, the remainder will be 1, and "Odd" will be printed.
Example
Following is an example to verify whether a given number is even or odd using the modulo ("%") operator:/p>
#include <iostream> using namespace std; int main() { int a = 1273; cout << "Given Number: " << a; string ans[] = {"Even","Odd"}; cout << " is "<< ans[a % 2] << endl; return 0; }
Following is the output of the above program:/p>
Given Number: 1273 is Odd
Using Bitwise Operation
We already know that if the least significant bit (LSB) of a number is set to 1, the number is odd. If the LSB is 0, then the number is even. Here we are going to use the Bitwise Operation to check the LSB.
Steps
Following are the steps:/p>
- Declare an array with two values, "Even" and "Odd".
- We will use LSB to access the appropriate index in this array.
- Check the bit-wise AND of the number with 1.
- This operation will give 0 if the number is even and 1 if the number is odd.
- Use the result as an index to get and print the appropriate value from the array.
Example
Following is an example to verify whether a given number is even or odd using the bit-wise operation:br>
#include <iostream> using namespace std; int main() { int num = 75400; cout << "Given Number: " << num; string ans[] = {"Even", "Odd"}; int res = num & 1; cout << " is " << ans[res] << endl; return 0; }
Following is the output of the above code:/p>
Given Number: 75400 is Even