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

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this basic C++ program, we will have a look at how to check whether number is even or odd. In this program, the if…else statement is used to check whether a number entered by the user is even or odd.

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

#include <iostream>
using namespace std;
int main()
{
    int n;
    cout << "Enter an integer: ";
    cin >> n;
    if ( n % 2 == 0)
        cout << n << " is even.";
    else
        cout << n << " is odd.";
    return 0;
}

Leave a Comment

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