C++ Program to find odd or even number without using modulus operator

Submitted by Abhishek Pathak, on April 06, 2017

This program will read an integer number and check whether it is EVEN or ODD without using Modulus (%) Operator.

Program for finding odd or even number is one of the basic programs that every programmer must know. Currently, we all have been doing it with the help of % operator (modulus or remainder operator). But, most of the people might not know there is another quick way to find whether a given number is odd or even.

Program to find EVEN or ODD without using Modulus (%) Operator in C++

using namespace std;

int main() 
	int n; 
	cout<<"Enter Number: ";

		n = n-2;

		cout<<"Even Number"<<endl;
		cout<<"Odd Number"<<endl;

	return 0;


First Run:
Enter Number: 101 
Odd Number

Second Run:
Enter Number: 102 
Even Number

In this program, we are simply reducing the given number by 2 until it is either 0 or 1. If it is even, the end result will be 0 and if it is odd, the loop will not go to negative number, therefore the result for odd will be 1.

Then we are simply checking if number (n) is 0, it is even and if it is 1, the number is odd.

Related Programs


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.