Conditional operator programming exercises
C Program to Check Character is Alphabet, Digit or Special Character using Conditional operator
Write a C Program to Check Character is Alphabet Digit or Special Character using Conditional/Ternary operator ?:. How to check alphabets using conditional operator in C programming.
Required knowledge
Operators, Data Types in c, Variables in C, Basic input/output
C Program to Check Character is Alphabet, Digit or Special Character using conditional operator
/** * C Program to Check Character is Alphabet,Digit or * Special Character using conditional operator */ #include <stdio.h> #include <conio.h> int main() { char ch; clrscr(); /* * Input character from user */ printf("\n Enter any character: "); scanf("%c", &ch); /* * If (ch>='a' && ch<='z'||ch>='A' && ch<='Z') then * print Alphabit * else (ch>='0'&&ch<='9') then * print digit * else * print Special Character */ (ch>='a' && ch<='z'||ch>='A' && ch<='Z') ? printf("%c is Alphabit",ch) : (ch>='0'&&ch<='9' ) ? printf("%c is digit",ch) : printf("%c is Special Character",ch); getch(); return 0; }
Output:
Enter any character: a a Alphabit