Any number that is divisible by 2 leaving no remainder is called Even number and any number that cannot be divided by 2 is called Odd number.
In this articles we will write a C++ program to find if the given number is Even or Odd.
#include <iostream> #include <conio.h> using namespace std; int main() { int n; cout<<"Program to find Even and Odd number"<<endl; cout<<"Enter Any Number"<<endl; cout<<"Number: "; cin>>n; if (n%2==0) { cout<<"The number is Even"; } else { cout<<"The number is Odd"; } getch(); return 0; }
Explanation
When the program start, it will ask for the number from the user.
After the user input the number, the program will perform a modulo division on the given number
If the modulo division is 0, then the number is even, else the number is odd
Compiler Used: CodeBlock