C++ and Python Program to Check Whether the Number is Even or Odd

Posted in

C++ and Python Program to Check Whether the Number is Even or Odd

Vinay Khatri
Last updated on September 24, 2022

    In this program, we will code to check whether the entered number is even or odd. An even number is that number that is divisible by 2, and an odd number is that number that is not divisible by 2.

    C++ Program to Check Whether the Number is Even or Odd

    #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 Program to Check Whether the Number is Even or Odd

    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:

    Leave a Comment on this Post

    0 Comments