Check whether given number is even or odd

Check whether given number is even or odd” is a very basic programming exercise problem for beginners. Here, we are given a number, entered by user and our task is to write a program to check whether a given number is even or odd.

Even number: A number which is divisible by 2.

Odd number: A number which is not divisible by 2.

Example:

INPUT:
Number = 4
OUTPUT:
4 is even number
INPUT:
Number = 7
OUTPUT:
7 is odd number.

We can simply check the divisibility condition to check whether a number is even or odd.

C++ Program to check whether a number is even or odd is as follows:

#include<bits/stdc++.h>  
using namespace std;  
int main()  
{  
    int num;  
      
    //Scan the number  
    cout<<"Enter the number:";  
    cin>>num;  
      
    // Even : Divisible by 2  
    if(num % 2 == 0)  
    {  
        cout<<num<<" is even number";  
    }  
    // Odd : Not Divisible by 2  
    else if(num % 2 != 0)  
    {  
        cout<<num<<" is odd number";  
    }  
}  
OUTPUT:
Enter the number: 4
4 is even number

Related Posts:

  1. Program to check whether entered number is prime number or not.
  2. Program to check whether entered number is palindrome or not.
  3. Program to check whether entered number is Armstrong Number or Not.
  4. Program to convert binary number to octal number.
  5. Program to convert binary number to decimal number.
  6. Program to convert binary number to hexadecimal number.
  7. Program to convert octal number to binary number.
  8. Program to convert octal number to decimal number.
  9. Program to convert octal number to hexadecimal number.
  10. Program to convert decimal number to binary number.
  11. Program to convert decimal number to octal number.
  12. Program to convert decimal number to hexadecimal number.
  13. Program to convert hexadecimal number to binary number.
  14. Program to convert hexadecimal number to octal number.
  15. Program to convert hexadecimal number to decimal number.
  16. Program to check Leap Year.
  17. Program to find largest amongst three numbers.
  18. Program to find factorial of a number.
  19. Program to find GCD of two numbers.
  20. Program to find LCM of two numbers.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *