In this program, we will code to check whether the entered number is an even or odd. An even number is that number which is divisible by 2 and an odd number is that number which is not divisible by 2. C++:
#include<iostream.h> #include< conio.h> #include<stdio.h> #include<math.h> void main() { clrscr(); int num; cout<<"Enter a number: "; cin>>num; if(num%2==0) cout<<"It is an even number"; else cout<<"It is an odd number"; getch(); }
Output:
Enter a number: 24 It is an even number
Python:
num=int(input("Enter a number: ")) if num%2==0: print("It is an even number") else: print("It is an odd number")
Output:
Enter a number: 123 It is an odd number
People are also reading:
- Python Examples
- Python RegEx
- How many Centimeters in a Foot through Python?
- Rectangle & Pyramids Pattern in C++
- C Program to Convert Feet into Inches
- C Program to Extract a Portion of String
- C++ and Python Code to Find The Sum of Elements Above and Below The Main Diagonal of a Matrix
- Linear Search in Python and C++
- Binary Search in C
- Perfect Number in C
Leave a Comment on this Post