Site icon Study Algorithms

Write a program to find the case of a character entered from the keyboard.

Question: Write a program that returns the case of the character?

Input: e
Output: lower case

We shall use the concept of ASCII characters to determine the case of the character input by the user. The ASCII table can be found at this link. ASCII TABLE
From this we can see the following ASCII codes:-

CHARACTER ASCII CODE
A 65
Z 90
a 97
z 122

Thus, to check the case we simply compare the ASCII codes. Since we are using C language, in C every character is considered as an integer.

Here is an implementation:-

void printCase(char c)
{
    if(c>=65 && c<=90)
        printf("UPPER CASE");
    else if(c>=97 && c<=122)
        printf("lower case");
    else
        printf("Some other symbol");
}
Exit mobile version