Program to print Even or odd number in C++.

 

To check whether an integer is even or odd, the remainder is calculated when it is divided by 2 using modulus operator %. If remainder is zero, Then that integer is even if not that integer is odd.

 

 

Let’s write a program which print Even or odd numbers in C++.

 

Step 1: Let’s open turboC++ and write the following Code .

 

// Add preprocessor

 

#include<iostream.h>

#include<conio.h>

void main()

{

long int a;

 

//Clear Screen

clrscr();

 

cout<<”provide input:”;

cin>>a;

if (a%2==0)

{
cout<<”this is an even number:”;

}

else

{

cout<<”this is an odd number:”;

}

getch();

}

 

 

Step 2: Run the program and see output:

 

Output:

 

output

 

Happy Coding.

 

 

 

 

Tags: ,