
All characters whether alphabet, digit or special character have ASCII value. Input character from the user will determine if it’s Alphabet, Number or Special character.
ASCII value ranges-
- For capital alphabets 65 – 90
- For small alphabets 97 – 122
- For digits 48 – 57
All other cases are Special Characters.
Examples :
Input : 8 Output : Digit Input : E Output : Alphabet
C++
// CPP program to find type of input character #include <iostream> using namespace std; void charCheck(char input_char) { // CHECKING FOR ALPHABET if ((input_char >= 65 && input_char <= 90) || (input_char >= 97 && input_char <= 122)) cout << " Alphabet "; // CHECKING FOR DIGITS else if (input_char >= 48 && input_char <= 57) cout << " Digit "; // OTHERWISE SPECIAL CHARACTER else cout << " Special Character "; } // Driver Code int main() { char input_char = '$'; charCheck(input_char); return 0; } |
Java
// Java program to find type of input character import java.io.*; class GFG { static void charCheck(char input_char) { // CHECKING FOR ALPHABET if ((input_char >= 65 && input_char <= 90) || (input_char >= 97 && input_char <= 122)) System.out.println(" Alphabet "); // CHECKING FOR DIGITS else if (input_char >= 48 && input_char <= 57) System.out.println(" Digit "); // OTHERWISE SPECIAL CHARACTER else System.out.println(" Special Character "); } // Driver Code public static void main(String[] args) { char input_char = '$'; charCheck(input_char); } } // This code is contributed by vt_m. |
Python3
# python program to find type of # input character def charCheck(input_char): # CHECKING FOR ALPHABET if ((int(ord(input_char)) >= 65 and int(ord(input_char)) <= 90) or (int(ord(input_char)) >= 97 and int(ord(input_char)) <= 122)): print( " Alphabet ") # CHECKING FOR DIGITS elif (int(ord(input_char)) >= 48 and int(ord(input_char)) <= 57): print(" Digit ") # OTHERWISE SPECIAL CHARACTER else: print(" Special Character ") # Driver Code input_char = '$'charCheck(input_char) # This code is contributed by Sam007. |
C#
// C# program to find type of // input character using System; class GFG { // Function to check type // of input character static void charCheck(char input_char) { // Checking for Alphabet if ((input_char >= 65 && input_char <= 90) || (input_char >= 97 && input_char <= 122)) Console.WriteLine(" Alphabet "); // Checking for Digits else if (input_char >= 48 && input_char <= 57) Console.WriteLine(" Digit "); // Otherwise Special Character else Console.WriteLine("Special Character"); } // Driver Code public static void Main() { char input_char = '$'; charCheck(input_char); } } // This code is contributed by vt_m. |
PHP
<?php // PHP program to find type // of input character function charCheck($input_char) { // CHECKING FOR ALPHABET if (($input_char >= 65 && $input_char <= 90) || ($input_char >= 97 && $input_char <= 122)) echo " Alphabet "; // CHECKING FOR DIGITS else if ($input_char >= 48 && $input_char <= 57) echo " Digit "; // OTHERWISE SPECIAL CHARACTER else echo " Special Character "; } // Driver Code $input_char = '$'; charCheck($input_char); // This code is contributed by Sam007 ?> |
Output :
Special Character
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Check if frequency of each character is equal to its position in English Alphabet
- Check whether the given character is in upper case, lower case or non alphabetic character
- Count Uppercase, Lowercase, special character and numeric values
- Check whether the Average Character of the String is present or not
- Special two digit number
- Character arithmetic in C and C++
- Replace a character c1 with c2 and c2 with c1 in a string S
- Character Classification in C++ : cctype
- Find the Nth occurrence of a character in the given String
- Print last character of each word in a string
- Convert character array to string in C++
- getline() function and character array
- Print the first and last character of each word in a String
- Program to print ASCII Value of a character
- Frequency of each character in a String using unordered_map in C++
- How to convert a single character to string in C++?
- Type difference of character literals in C and C++
- Data type of character constants in C and C++
- Change/add only one character and print '*' exactly 20 times
- Program to count occurrence of a given character in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

