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:
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter an integer: ";
cin >> number;
// True if the number is divisible by 2
if(number % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}
Output:
Enter an integer number: -53 -53 is odd.