17.Write a program to in C check if a character is uppercase or lowercase using switch case.
Purpose:
The purpose of the program is to determine whether a given character is uppercase or lowercase. This can be useful in text processing applications, data validation, and input handling scenarios where different actions need to be taken based on the case of the characters.
Agenda:
1. It do ask the user to enter any character.
2. Use a 'switch-case' statement to check the ASCII value of the character.
3. If the ASCII value falls within the range of uppercase letters (65-90), display a message indicating that the character is uppercase.
4. If the ASCII value falls within the range of lowercase letters (97-122), display a message indicating that the character is lowercase.
5. If the character is neither uppercase nor lowercase, display a message indicating that it is not a letter.
Real-life applications:
In a text editor application, the program can be used to check the case of characters entered by the user. This can help in implementing features like auto-correct, formatting, or highlighting based on the case of the characters.
A program to in C check if a character is uppercase or lowercase using switch case.
/* C language program to check if a character is uppercase or lowercase using switch case.*/
#include <stdio.h>
int main()
{
int num;
char ch;
printf("\nEnter a character: \n");
scanf("%c", &ch);
switch(ch) {
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
printf("The character %c is uppercase.\n",ch);
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
printf("\nThe character %c is lowercase.\n",ch);
break;
default:
printf("\nThe character %c is neither upperca or lower case",ch);
return 0;
}
Output
Enter a character: a
The character a is lowercase.