python Program to check if a Number Is Positive Or Negative Even or Odd
Check if a Number is Even or Odd in C
Given an integer input, the objective is to write a code to Check if a Number is Even or Odd in C Language.
For Instance,
Input: Num = -5
Output: The number is Negative
Check if a Number is Even or Odd in C
Given an integer input, the objective is to check whether the given integer is Even or Odd. In order to do so we have the following methods:
- Method 1: Using Brute Force
- Method 2: Using Nested if-else Statements
- Method 3: Using the ternary operator
Python Program to Check Whether a Number is Even or Odd
Given an integer input, the objective is to write a Python program to check whether a number is Even or Odd.
Method 1: Using Brute Force
num = int(input("Enter a Number:")) if num % 2 == 0: print("Given number is Even") else: print("Given number is Odd")
Output:
Enter a Number: 5 Given number is Odd
Method 2: Using Ternary Operator
num = 17 print("Even") if num % 2 == 0 else print("Odd")
Output:
Odd
Method 3: Using Bitwise Operator
def isEven(num): return not num & 1 if __name__ == "__main__": num = 13 if isEven(num): print("Even") else: print("Odd")
Output:
Odd