Check Even Odd Number using CPP

    1. Home
    2. Tutorials
    3. CPP
    4. CPP Programs
    5. If Else Statement
    6. Program

    Source Code

    #include <iostream>

    using namespace std;

    int main(int argc, char** argv) {
        
        // Variable Declaration for input
        int n;
        cout<<"Enter Number: ";
        cin>>n;

        if(n%2 == 0)
            cout<<"Even\n";
        else
            cout<<"Odd\n";
        
        return 0;
    }

    Output

    check even odd number using if else statement in c++Working

    This program declare one variable of int type. This variable is named as n and will used to store input value. After declaration input statement is used to get input. At last we will check whether it is even or odd.

    Number is even if it it's remainder with 2 is zero (means it is completely divided by 2) otherwise it will be Odd. For this purpose modulus (Remainder) operator is used in C++.

    Remainder operator

    Some examples of remainder operator is given to understand it's functionality in program.

    Sr. Expression Remainder
    1 10 % 3 1
    2 12 % 4 0
    3 19 % 10 9
    4 20 % 5 4
    5 100 % 10 0

     

     

     

    Comments
    Login to TRACK of Comments.