Even number
Even numbers are numbers that have a difference of 2 unit or number. In other words, if the number is completely divisible by 2 then it is an even number.
Odd number
Opposite of even numbers, odd numbers are having a difference of 3 unit or number. In other words, if the number is not completely divisible by 2 then it is an odd number.
Logic
To find if a number is even or odd we only need to check if the given number is multiple of 2 or not, If it is multiple of 2 that means it is even number otherwise an odd number.
To check if it is multiple of 2 or not we use modulus operator.
If the expression number % 2 returns 0 that means the number is a multiple of 2. In other words, it is completely divisible by 2.
Program
#include <iostream> using namespace std; int main() { int number; cout << "Enter an integer : "; cin >> number; if (number % 2 == 0) { cout << endl << number << " is even number."; } else { cout << endl << number << " is odd number."; } return 0; }
Output
Enter an integer : 886
886 is even number.