Reads an integer and determines and prints whether it's odd or even. - C++ Data Type

C++ examples for Data Type:int

Description

Reads an integer and determines and prints whether it's odd or even.

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    int num1;//from   w w w  . java  2  s.c om

    std::cout << "Enter an integer: ";
    std::cin >> num1;

    std::cout << num1 << " is " << ((num1 % 2 == 0) ? "even" : "odd")
              << std::endl;

    return 0;
}

Result


Related Tutorials