Last Updated: 9 May, 2023

Odd Even

Easy
Asked in company
BigDataLogin

Problem statement

You are given an integer 'N'.


Return 'odd' if the given number 'N' is odd, else return 'even'.


For Example:
N=5

Output: odd
Input format:
The first line contains an integer 'N’, denoting the number.
Output Format:
The output contains a string “odd” or “even”.
Note:-
You don’t need to print anything. Just implement the given function.  

Approaches

01 Approach

Approach:

Find the modulus of ‘N’ with 2. If it comes out 1 then it's “odd” else “even”.

 

Algorithm:

  • If (N mod 2) is equal to 1
    • return “odd”
  • else
    • return “even”

02 Approach

Approach:

Find the &(bitwise AND) of ‘N’ with 1. If it comes out 1 then it's “odd” else “even”.

 

Algorithm:

  • If (N & 1) is equal to 1
    • return “odd”
  • else
    • return “even”