C++ Online Compiler
Example: C++ Program to Check Whether Number is Even or Odd using Ternary Operator
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Check Whether Number is Even or Odd using Ternary Operator #include <iostream> using namespace std; int main() { int x; cout << "Enter an integer number to check ::\n"; cin >> x; x = x % 2 == 0 ? 1 : 0; if (x) { cout << "The input number is even.\n"; } else { cout << "The input number is odd.\n"; } return 0; }
6
Output
Clear
ADVERTISEMENTS