codescracker


c++

C++ Program to Check Even or Odd



« Previous Program Next Program »


Check Even or Odd in C++

To check whether the input number is an even or an odd number in C++ programming, you have to ask to the user to enter a number. Now to check for even or odd, follow these rules:

as shown here in the following program.

C++ Programming Code to Check Even or Odd

Following C++ program ask to the user to enter a number, to check and display whether the entered number is an even number or an odd number:

/* C++ Program - Check Even or Odd */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int num;
	cout<<"Enter a number :";
	cin>>num;
	if(num%2==0)
	{
		cout<<"This is an even number";
	}
	else
	{
		cout<<"This is an odd number";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result. Above C++ Programming Example Output (for even):

C++ program check odd even

Above C++ Programming Example Output (for odd):

C++ program odd even

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test