The Wayback Machine - https://web.archive.org/web/20241119094756/https://www.geeksforgeeks.org/program-check-input-character-alphabet-digit-special-character/
Open In App

Check input character is alphabet, digit or special character

Last Updated : 17 Feb, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

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 
?> 


Javascript




<script>
      // JavaScript program to find type of input character
      function charCheck(input)
      {
        var input_char = input.charCodeAt(0);
          
        // CHECKING FOR ALPHABET
        if (
          (input_char >= 65 && input_char <= 90) ||
          (input_char >= 97 && input_char <= 122)
        )
          document.write(" Alphabet ");
            
        // CHECKING FOR DIGITS
        else if (input_char >= 48 && input_char <= 57)
          document.write(" Digit ");
            
        // OTHERWISE SPECIAL CHARACTER
        else document.write(" Special Character ");
      }
  
      // Driver Code
      var input_char = "$";
      charCheck(input_char);
        
      // This code is contributed by rdtank.
    </script>


Output : 
 

 Special Character 

Time complexity: O(1) as constant operations are done

Auxiliary space: O(1)
 



Previous Article
Next Article

Similar Reads

Check if frequency of each character is equal to its position in English Alphabet
Given string str of lowercase alphabets, the task is to check if the frequency of each distinct characters in the string equals to its position in the English Alphabet. If valid, then print "Yes", else print "No". Examples: Input: str = "abbcccdddd" Output: Yes Explanation: Since frequency of each distinct character is equals to its position in Eng
8 min read
Count of N-digit numbers having digit XOR as single digit
Given an integer N, the task is to find the total count of N-Digit numbers such that the Bitwise XOR of the digits of the numbers is a single digit. Examples: Input: N = 1Output: 9Explanation: 1, 2, 3, 4, 5, 6, 7, 8, 9 are the numbers. Input: N = 2Output: 66Explanation: There are 66 such 2-digit numbers whose Xor of digits is a single digit number.
14 min read
Count ways to generate N digit number such that its every digit divisible by previous digit
Given a number N, the task is to count the number of ways to create an N digit number from digits 1 to 9 such that every digit is divisible by its previous digit that is if the number is represented by an array of digits A then A[i + 1] % A[i] == 0. print the answer modulo 109 + 7. Examples: Input: N = 2Output: 23Explanation: For N = 2 possible ans
15+ min read
Smallest alphabet greater than a given character
Given a list of sorted characters consisting of both Uppercase and Lowercase Alphabets and a particular target value, say K, the task is to find the smallest element in the list that is larger than K. Letters also wrap around. For example, if K = 'z' and letters = ['A', 'r', 'z'], then the answer would be 'A'. Examples: Input : Letters = ["D", "J",
10 min read
Remove character in a String except Alphabet
Given a string consisting of alphabets and other characters, remove all the characters other than alphabets and print the string so formed. Example Input: str = "$Gee*k;s..fo, r'Ge^eks?" Output: GeeksforGeeks Program to Remove characters in a string except alphabetsBelow are the steps and methods by which we can remove all characters other than alp
2 min read
Special two digit number
A special two-digit number is a number such that when the sum of the digits of the number is added to the product of its digits, the result is equal to the original two-digit number. Examples : input : 59. output : 59 is a Special Two-Digit Number Explanation: Sum of digits = 5 + 9 = 14 Product of its digits = 5 x 9 = 45 Sum of the sum of digits an
6 min read
Special two digit numbers in a Binary Search Tree
Given a Binary Search Tree, the task is to count the number of nodes which are having special two-digit numbers.Note: Special two-digit numbers are those numbers that satisfy the condition that the sum of their digits added to the product of their digits equals the original number.Prerequisite: Special Two Digit Number | Binary Search Tree | Exampl
8 min read
Check if the given Trie contains words starting from every alphabet
Given a Trie, the task is to check if it contains words starting from every alphabet from [a - z]. Examples: Input: keys[] = {"element", "fog", "great", "hi", "ok", "ios", "parrot", "quiz", "kim", "mango", "nature", "apple", "ball", "cat", "dog", "lime", "ruby", "shine", "tinkter", "ultra", "volly", "wow", "xerox", "yak", "zenon", "joke"} Output: Y
8 min read
Check if frequency of each digit is less than the digit
Given an integer n, the task is to check if frequency of each digit of the number is less than or equal to digit itself. Examples: Input : 51241 Output : False Input : 1425243 Output : True Naive Approach: Start from 0 and count the frequency for every digit upto 9, if at any place frequency is more than the digit value then return false, else retu
8 min read
Match Expression where a single special character in pattern can match one or more characters
Given two string, in which one is a pattern (Pattern) and the other is a searching expression. Searching expression contains '#'.The # works in the following way: A # matches with one or more characters.A # matches all characters before a pattern match is found. For example, if pat = "A#B", and text is "ACCBB", then # would match only with "CC" and
8 min read
Count Uppercase, Lowercase, special character and numeric values
Given a string, write a program to count the occurrence of Lowercase characters, Uppercase characters, Special characters, and Numeric values. Examples: Input : #GeeKs01fOr@gEEks07 Output : Upper case letters : 5 Lower case letters : 8 Numbers : 4 Special Characters : 2 Input : *GeEkS4GeEkS* Output : Upper case letters : 6 Lower case letters : 4 Nu
5 min read
Count characters at same position as in English alphabet
Given a string of lower and uppercase characters, the task is to find how many characters are in the same position as in the English alphabet. Examples: Input: ABcED Output : 3 First three characters are at same position as in English alphabets. Input: geeksforgeeks Output : 1 Only 'f' is at same position as in English alphabet Input : alphabetical
7 min read
Program to print alphabet "A" using stars
Given the number of lines n, print the alphabet A pattern using stars.Examples : Input : Number of lines : 5 Output : * * * *** * * * * Input : Number of lines : 10 Output : **** * * * * * * * * ****** * * * * * * * * C/C++ Code // CPP program to print alphabet A pattern #include <iostream> using namespace std; // Function to display alphabet
5 min read
Latin alphabet cipher
The Latin Alphabet Cipher Encryption Technique is one of the earliest and simplest techniques of encrypting data. It’s simply a type of substitution cipher technique, i.e., each letter of a given text is substituted by its corresponding number as represented in its alphabetical order. For Example, we have given a string as "hello everyone", then it
5 min read
Find alphabet in a Matrix which has maximum number of stars around it
Given a matrix mat consisting of * and lowercase English alphabets, the task is to find the character which has the maximum number of * around it (including diagonal elements too). If two characters have same maximum count, print lexicographically smallest character. Source: D-E Shaw Interview Experience Examples: Input: mat[][] = {{'b', '*', '*',
15+ min read
Find the most valued alphabet in the String
Given a string str, the task is to find the maximum valued alphabet in str. The value of a particular alphabet is defined as the difference in the indices of its last and the first occurrence. If there are multiple such alphabets then find the lexicographically smallest alphabet. Examples: Input: str = "abbba" Output: a value('a') = 4 - 0 = 4 value
7 min read
Find letter's position in Alphabet using Bit operation
Given a string of English alphabets. The task is, for every character in the string print its position in the English alphabets.Note: The characters in the string are considered to be case-insensitive. That is, both 'A' and 'a' is at the first position.Examples: Input: "Geeks" Output: 7 5 5 11 19 'G' is the 7th character of the alphabets 'e' is the
3 min read
Find the Mid-Alphabet for each index of the given Pair of Strings
Given two same-length strings str1 and str2 consisting of lowercase English alphabets, the task is to find the Mid-Alphabet for each index of the given pair of Strings. Examples: Input: str1 = "abcd", str2 = "cdef" Output: bcde Explanation: b is mid of a and c c is mid of b and d d is mid of c and e e is mid of e and f Input: str1 = "akzbqzgw", str
4 min read
Minimize replacement of characters to its nearest alphabet to make a string palindromic
Given a string S of length N consisting of lowercase alphabets, the task is to find the minimum number of operations to convert the given string into a palindrome. In one operation, choose any character and replace it by its next or previous alphabet. Note: The alphabets are cyclic i.e., if z is incremented then it becomes a and if a is decremented
6 min read
Minimize replacements by previous or next alphabet required to make all characters of a string the same
Given a string S of length N consisting of lowercase alphabets, the task is to find the minimum number of operations required to make all the characters of the string S the same. In each operation, choose any character and replace it with its next or previous alphabet. Note: The alphabets are considered to be cyclic i.e., Next character of z is con
6 min read
Lexicographically smallest String using all of the first K letters of alphabet and no two adjacent characters are same
Given two integers N and K, the task is to form a string of size N using the first K characters of the alphabet following the given conditions: No two adjacent characters of the string are the same.All of the K characters are present at least once in the string. If no such string is possible, print -1. Examples: Input: N = 3, K = 2Output: "aba"Expl
7 min read
Count Substrings with at least one occurrence of first K alphabet
Given a string S of size N and a positive integer K. The given string only consists of the first K English lowercase alphabets. The task is to find the number of substrings that contain at least one occurrence of all these K characters. Examples: Input: S = "abcabc", K = 3Output: 10Explanation: The substrings containing at least one occurrence of t
15+ min read
For each lowercase English alphabet find the count of strings having these alphabets
Given an array of strings of lowercase English alphabets. The task is for each letter [a-z] to find the count of strings having these letters.Examples: Input: str = { "geeks", "for", "code" } Output: { 0 0 1 1 2 1 1 0 0 0 0 0 0 0 2 0 0 1 1 0 0 0 0 0 0 0 } Explanation: For a letter, say 'e', it is present in { "geeks", "code" }, hence its count is 2
11 min read
Count Strings that does not contain any alphabet's both uppercase and lowercase
Given an array of strings arr[], containing N strings, the task is to count the number of strings that do not contain both the uppercase and the lowercase character of an alphabet. Example: Input: arr[]={ "abcdA", "abcd", "abcdB", "abc" }Output: 2Explanation: The first string contains both the uppercase and the lowercase character for alphabet 'a'.
11 min read
Count n digit numbers not having a particular digit
We are given two integers n and d, we need to count all n digit numbers that do not have digit d. Example : Input : n = 2, d = 7 Output : 72 All two digit numbers that don't have 7 as digit are 10, 11, 12, 13, 14, 15, 16, 18, ..... Input : n = 3, d = 9 Output : 648 A simple solution is to traverse through all d digit numbers. For every number, chec
8 min read
Largest number less than N with digit sum greater than the digit sum of N
Given an integer N, the task is to find the greatest number less than N such that the sum of its digits is greater than the sum of the digits of N. If the condition isn't satisfied for any number then print -1.Examples: Input: N = 100 Output: 99 99 is the largest number less than 100 sum of whose digits is greater than the sum of the digits of 100I
9 min read
Count of Numbers in Range where first digit is equal to last digit of the number
Given a range represented by two positive integers L and R. Find the count of numbers in the range where the first digit is equal to the last digit of the number. Examples: Input : L = 2, R = 60 Output : 13 Explanation : Required numbers are 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44 and 55 Input : L = 1, R = 1000 Output : 108 Prerequisites: Digit DPTh
15+ min read
Count numbers in a range with digit sum divisible by K having first and last digit different
Given a range in the form of L and R, and a value K, the task is to count the numbers between the range L to R such that the sum of the digit is divisible by K, and the first digit is not equal to the last digit of the number. Examples: Input: L = 1, R = 10, K = 2 Output: 0 Explanation: The input numbers whose sum of the digits are divisible by 2 (
15 min read
Find the remainder when First digit of a number is divided by its Last digit
Given a number N, find the remainder when the first digit of N is divided by its last digit.Examples: Input: N = 1234 Output: 1 First digit = 1 Last digit = 4 Remainder = 1 % 4 = 1 Input: N = 5223 Output: 2 First digit = 5 Last digit = 3 Remainder = 5 % 3 = 2 Approach: Find the first digit and the last digit of the number. Find then the remainder w
5 min read
Find all numbers between range L to R such that sum of digit and sum of square of digit is prime
Given the range L and R, count all numbers between L to R such that sum of digits of each number and sum of square of digits of each number is Prime.Note: 10 <= [L, R] <= 108 Examples: Input: L = 10, R = 20 Output: 4 Such types of numbers are: 11 12 14 16 Input: L = 100, R = 130 Output: 9Such types of numbers are : 101 102 104 106 110 111 113
9 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg