C++ Program to check number is even or odd


In this example, You will learn How to check a number is even or odd in C++.


12 % 2 == 0

14 % 2 == 0

Example: Check number is even or Odd in C++.

#include<iostream>
using namespace std;

int main() {

  int n;
  cout << "Enter a number:";
  cin>>n;

  if (n % 2 == 0) {
      cout << "Number is even:" << n;
  } else {
      cout << "Number is odd:" << n;
  }

  return 0;
}

Output:

Enter a number:14
Number is even:14