C++ program to take a number as input and tells its even or odd number

Views: 116   

Following program shows you how to take a number as input and tells its even or odd number.
This program divides input by 2, If remainder is zero it prints even otherwise it prints odd

#include <iostream>

int main() {
    int input;
    std::cout << "Enter a number:";
    std::cin >> input;
    if (input % 2 == 0) {
        std::cout << "even";
    } else {
        std::cout << "odd";
    }
}

Output:

Example1:

Enter a number: 6
even

Example2:

Enter a number: 23
odd
On By