C++ program to check given number is even or odd

C++ Program to check given number is even or odd

        To check any number is even or odd only one condition is tested. If the number is completely divisible by 2 the number is even else the number is odd. For this modulo operator is used you can learn more about this operator here modulo operator in C++


Code

#include <iostream>
using namespace std;


int main() {
    
    cout<<
"Enter a number: ";                       //Requesting a Number
    cout<<endl;
    int n;
    cin>>n;
    
    if(n%2==0){                                                             //condition to check even or odd
        cout<<"It is an Even Number"<<endl;                     //if even print even
    }
    else{
        cout<<"It is an Odd Number"<<endl;                  //if odd print odd
    }
    
    return 0;
}



Input:

Enter a number: 

11

Output: 

It is an Odd Number

Post a Comment

0 Comments