C program to check alphabets using Conditional operator

Write a C program to input a character and check whether the character is alphabet or not using Conditional/Ternary operator ?:. How to check alphabets using conditional operator in C programming.

Example

Input

Enter any character: a

Output

It is ALPHABET

Required knowledge

Basic C programming, Conditional operator, Logical operators

Program to check alphabets using conditional operator

/**
 * C program to check alphabets using Conditional operator
 */

#include <stdio.h>

int main()
{
    char ch;
    
    /*
     * Input character from user
     */
    printf("Enter any character: ");
    scanf("%c", &ch);
    
    /*
     * If (ch>'a' and ch<'z') or (ch>'A' and ch<'Z') then
     *     print alphabet
     * else
     *     print not alphabet
     */
    (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') 
        ? printf("It is ALPHABET")
        : printf("It is NOT ALPHABET");

    return 0;
}

Output

Enter any character: a
It is ALPHABET

Happy coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols. as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.

Follow on: Facebook | Twitter | Google | or

Comments and discussion
Have a doubt, write here. I will help my best.
Before commenting you must escape your source code before commenting. Paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>