Check whether a given character is upper case, lower case, number or special character

Program to check whether a given character is upper case, lower case, number or special character is discussed here.

DESCRIPTION

If it is an alphabet and find whether it is an Uppercase alphabet or Lowercase alphabet.

If it is a number display Number else display Symbol.

Input & Output format:

Input consists of one character.

Sample Input :

A

Sample Output :

Upper

Algorithm to check whether a given character is upper case, lower case, number or special character 

  • Input the character.
  • Find the ASCII value of the character.
  • If the ASCII value of the character is between 65 and 90, print “Upper”.
  • If the ASCII value of the character is between 97 and 122, print “Lower”.
  • If the ASCII value of the character is between 48 and 57, print “Number”.
  • Else, print “Symbol”.

Program to check whether a given character is upper case, lower case, number or special character is given below

// C program to check whether a given character is upper case, lower case, number or special character 

#include
int main()
{
//Fill the code
char ch;
scanf(“%c”,&ch);
if(ch >= 65 && ch <= 90)
printf(“Upper”);
else if(ch >= 97 && ch <= 122)
printf(“Lower”);
else if(ch >= 48 && ch <= 57)
printf(“Number”);
else
printf(“Symbol”);
return 0;
}

// C++ program to check whether a given character is upper case, lower case, number or special character 

#include<iostream>
using namespace std;
int main()
{
//Fill the code
char ch;
cin >> ch;
if(ch >= 65 && ch <= 90)
cout << “Upper”;
else if(ch >= 97 && ch <= 122)
cout << “Lower”;
else if(ch >= 48 && ch <= 57)
cout << “Number”;
else
cout << “Symbol”;
return 0;
}

// Java program to check whether a given character is upper case, lower case, number or special character 

import java.util.*;
public class Main
{
public static void main(String[] args)
{
char ch;
Scanner sc = new Scanner(System.in);
ch = sc.next().charAt(0);
if(ch >= 65 && ch <= 90)
System.out.print(“Upper”);
else if(ch >= 97 && ch <= 122)
System.out.print(“Lower”);
else if(ch >= 48 && ch <= 57)
System.out.print(“Number”);
else
System.out.print(“Symbol”);

}
}

# Python program to check whether a given character is upper case, lower case, number or special character 

ch = ‘#’
if(ord(ch) >= 65 and ord(ch) <= 90):
print(“Upper”)
elif(ord(ch) >= 97 and ord(ch) <= 122):
print(“Lower”)
elif(ord(ch) >= 48 and ord(ch) <= 57):
print(“Number”)
else:
print(“Symbol”)

Output:

check whether a given character is upper case, lower case, number or special character