Home » C++ programs » C++ Most popular & searched programs

C++ program to check EVEN or ODD

The numbers which are divisible by 2 are known as EVEN numbers while the numbers which are not divisible by 2 are known as ODD.

In this program, we will check whether a given number is EVEN or ODD. Here, we are checking EVEN or ODD by using three different methods.

Program to check EVEN or ODD using if else in C++



#include <iostream>
using namespace std;

int main()
{
	int num;
	cout<<"Enter an integer number: ";
	cin>>num;
	
	if(num%2==0)
		cout<<num<<" is an EVEN number."<<endl;
	else
		cout<<num<<" is an ODD number."<<endl;
	
	return 0;
}

Output

First run:
Enter an integer number: 10 
10 is an EVEN number. 

Second run:
Enter an integer number: 11 
11 is an ODD number.

Program to check EVEN or ODD using Ternary Operator in C++



(num%2==0)?
	(cout<<num<<" is an EVEN number."<<endl):
	(cout<<num<<" is an ODD number."<<endl);

Program to check EVEN or ODD using Bitwise AND Operator in C++



if(num & 0x01)
    cout<<num<<" is an ODD number."<<endl;
else
    cout<<num<<" is an EVEN number."<<endl;





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





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.