Even Odd Program in C++
In this C++ Programming tutorial we will see a Even Odd Program in C++ which checks whether a given number is Even or Odd. We will take the input number from the user and use the % (modulo) operator to check if the entered number is divisible by 2 or not in the if condition. If it is true we will print Even Number else we will print Odd Number.
Even Odd Program in C++
#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; }
Output
Enter an integer: 5
5 is odd.
5 is odd.