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.
Because,
10 = (2*5) + 0
Here Remainder is zero. So, 10 is divisible by 5.
Analysis
Let’s take first 10 numbers and perform modulo 2 operation.
Pictorial Explanation
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.
Procedure
Get input from user.
If num % 2 is zero, Print even
else, print odd
Example
Case 1
Input
10
Output
Even
Case 2
Input
13
Output
Odd
Case 3
Input
125
Output
Odd
Program
Example
#include<stdio.h> int main() { int num; scanf("%d",&num); if(num % 2 == 0) printf("Even"); else printf("Odd"); return 0; }