A Program to Check Whether a Number is Even or Odd

In this example, we are giving a program which is useful to check whether a number given by the user is even or odd.


Program to check even or odd:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int number;
  6. cout << "Enter an integer: ";
  7. cin >> number;
  8. // True if the number is divisible by 2
  9. if(number % 2 == 0)
  10. cout << n << " is even.";
  11. else
  12. cout << n << " is odd.";
  13. return 0;
  14. }

Output:

Enter an integer number: -53
			-53 is odd.