C program to check alphabets using Conditional operator

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.

Required knowledge

Operators, Data Types in c, Variables in C

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




Instagram