Odd or Even
A number which is divisible by 2 is known as even number.
If it’s not divisible by 2, it will be considered as odd numbers.
Divisible by N
In general, a number is divisible by N, if and only if the number % N becomes zero.
In other words, if we divide that number by N, the remainder should be zero.
Number = Divisor * Quotient + Remainder.
Any number can be expressed using this format,
Number = Q * D + R
10 is divisible by 5.
10 = (2*5) + 0
Here Remainder is zero. So, 10 is divisible by 5.
Let’s take first 10 numbers and perform modulo 2 operation.
If we observe the about results, we can notice that odd numbers are yielding remainder 1 while performing mod 2 operation.
And even numbers are resulting 0 while performing mod 2 operation.
Let’s a write code for this logic.
Get input from user.
If num % 2 is zero, Print even
else, print odd