Programs

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

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

You can easily check whether a number is even or odd by examining the remainder when the number is divided by 2. If the remainder is 0, the number is even; otherwise, it is odd. Below is a C++ program written for Turbo C++ to check whether a given number is even or odd:

#include <iostream.h>
#include <conio.h>

void main() {
    clrscr();  // Clear the screen (specific to Turbo C++)

    int num;

    cout << "Enter a number: ";
    cin >> num;

    // Check for even or odd
    if (num % 2 == 0) {
        cout << "The number is even." << endl;
    } else {
        cout << "The number is odd." << endl;
    }

    getch();  // Wait for user input (specific to Turbo C++)
}

To compile and run the program in Turbo C++:

  1. Open Turbo C++.
  2. Create a new file and copy-paste the above code into it.
  3. Save the file.
  4. Compile the code (usually by pressing Alt + F9).
  5. Run the program (usually by pressing Ctrl + F9).

After entering a number, the program will tell you whether the number is even or odd.