VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-whether-the-given-character-is-in-upper-case-lower-case-or-non-alphabetic-character/

⇱ Check whether the given character is in upper case, lower case or non alphabetic character - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check whether the given character is in upper case, lower case or non alphabetic character

Last Updated : 5 Dec, 2023

Given a character, the task is to check whether the given character is in upper case, lower case, or non-alphabetic character 

Examples:

Input: ch = 'A'
Output: A is an UpperCase character
Input: ch = 'a'
Output: a is an LowerCase character
Input: ch = '0'
Output: 0 is not an alphabetic character

Approach: The key to solving this problem lies in the ASCII value of a character. It is the simplest way to find out about a character. This problem is solved with the help of the following detail: 

  • Capital letter Alphabets (A-Z) lie in the range 65-91 of the ASCII value
  • Small letter Alphabets (a-z) lie in the range 97-122 of the ASCII value
  • Any other ASCII value is a non-alphabetic character.

Implementation:


Output
A is an UpperCase character
a is an LowerCase character
0 is not an alphabetic character

Time Complexity: O(1) as it is doing constant operations
Auxiliary Space: O(1)

Check whether the given character is in upper case, lower case, or non-alphabetic character using the inbuilt library: 


Output
A is an UpperCase character
a is an LowerCase character
0 is not an alphabetic character

Time Complexity: O(1)
Auxiliary Space: O(1)

This implementation uses a switch statement to check the value of the character. If it is an uppercase letter, it will print that it is an uppercase letter. If it is a lowercase letter, it will print that it is a lowercase letter. Otherwise, it will print that it is not an alphabetic character.


Output
A is an UpperCase character
a is a LowerCase character
0 is not an alphabetic character

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: