C program to check whether a character is Uppercase or Lowercase using Conditional operator

C program to check whether a character is Uppercase or Lowercase using Conditional operator

Write a C program to check whether a character is Uppercase or Lowercase 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 whether a character is Uppercase or Lowercase using conditional operator

/** * C program to check whether a character is Uppercase or * Lowercase 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') then * print Lowercase * else (ch>='A' && ch<='Z') then * print Uppercase * else * print is not alphabet */ (ch>='a' && ch<='z') ? printf("%c is Lowercase",ch) : (ch>='A' && ch<='Z') ? printf("%c is Uppercase",ch) : printf("%c is not alphabet",ch); getch(); return 0; }


Output:
Enter any character: a a is Lowercase




Instagram