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 <stdio.h> int main() { int number; printf("Enter an integer : "); scanf("%d", &number); if (number % 2 == 0) { printf("\n%d is even number.", number); } else { printf("\n%d is odd number.", number); } return 0; }
Output
Enter an integer : 886
886 is even number.