Check for Even Odd

Program to check if a number is even or odd

BeginnerTopic: Conditional Programs
Back

C++ Check for Even Odd Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
using namespace std;

int main() {
    int num;
    
    cout << "Enter a number: ";
    cin >> num;
    
    if (num % 2 == 0) {
        cout << num << " is even" << endl;
    } else {
        cout << num << " is odd" << endl;
    }
    
    return 0;
}
Output
Enter a number: 7
7 is odd

Understanding Check for Even Odd

This program uses the modulo operator (%) to check if a number is even or odd. If num % 2 equals 0, the number is even; otherwise, it's odd. This demonstrates basic conditional logic using if-else statements.

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Table of Contents