Write a program in C++ and python to check whether the number is even or odd

Posted in

Write a program in C++ and python to check whether the number is even or odd

Vinay Khatri
Last updated on June 10, 2022

    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:

    Leave a Comment on this Post

    0 Comments