C program to check alphabets using Conditional operator

Write a C program to enter any character and check whether character is alphabet or not using Conditional/Ternary operator ?:.

Example

Input

Enter any character: a

Output

It is ALPHABET

Required knowledge

Basic C programming, Conditional operator.

Program to check alphabets using conditional operator

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

#include <stdio.h>

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

    return 0;
}

Output

Enter any character: a
It is ALPHABET

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>