C++ Online Compiler
Example: C++ Program to Check Whether a Character is Alphabet or Not using Ternary Operator
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Check Whether a Character is Alphabet or Not using Ternary Operator #include <iostream> using namespace std; int main() { char x, f; // x - To store the input character cout << "-----Enter a character to check itself-----\n"; cin >> x; f = (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') ? 1 : 0; if (f) { cout << "\n" << x << " is an alphabet character.\n"; } else { cout << "\n" << x << " is not an alphabet character.\n"; } return 0; }
9
Output
Clear
ADVERTISEMENTS