Write a program to check whether a character is an alphabet, digit or special character

Write a program to check whether a character is an alphabet, digit or special character

Write C# Program to check whether a character is alphabet, digit or special character. I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System; public class charpexercise { static void Main(string[] args) { char ch; Console.WriteLine("Enter any character: "); ch = Convert.ToChar(Console.ReadLine()); // Alphabet checking condition if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { Console.WriteLine(ch + "is an Alphabet. "); } else if (ch >= '0' && ch <= '9') { Console.WriteLine(ch + "is a Digit. "); } else { Console.WriteLine(ch + "is a Special character.. "); } Console.ReadLine(); } }
Write a program to check whether a character is an alphabet, digit or special character
Write C# Program to check whether a character is alphabet, digit or special character

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 :ong> 
 

Input : 8 Output : Digit Input : E Output : Alphabet

void charCheck(char input_char)

    if ((input_char >= 65 && input_char <= 90)

        || (input_char >= 97 && input_char <= 122))

    else if (input_char >= 48 && input_char <= 57)

        cout << " Special Character ";

    static void charCheck(char input_char)

        if ((input_char >= 65 && input_char <= 90)

            || (input_char >= 97 && input_char <= 122))

            System.out.println(" Alphabet ");

        else if (input_char >= 48 && input_char <= 57)

            System.out.println(" Digit ");

            System.out.println(" Special Character ");

    public static void main(String[] args)

def charCheck(input_char):

    if ((int(ord(input_char)) >= 65 and

        int(ord(input_char)) <= 90) or

        (int(ord(input_char)) >= 97 and

        int(ord(input_char)) <= 122)):

    elif (int(ord(input_char)) >= 48 and

            int(ord(input_char)) <= 57):

        print(" Special Character ")

    static void charCheck(char input_char)

        if ((input_char >= 65 && input_char <= 90)

            || (input_char >= 97 && input_char <= 122))

            Console.WriteLine(" Alphabet ");

        else if (input_char >= 48 && input_char <= 57)

            Console.WriteLine(" Digit ");

            Console.WriteLine("Special Character");

    public static void Main()

function charCheck($input_char)

    if (($input_char >= 65 && $input_char <= 90)

        || ($input_char >= 97 && $input_char <= 122))

    else if ($input_char >= 48 &&

    echo " Special Character ";

      function charCheck(input)

        var input_char = input.charCodeAt(0);

          (input_char >= 65 && input_char <= 90) ||

          (input_char >= 97 && input_char <= 122)

          document.write(" Alphabet ");

        else if (input_char >= 48 && input_char <= 57)

          document.write(" Digit ");

        else document.write(" Special Character ");

Output : 
 

Special Character

Article Tags :

C program to check whether the character is the alphabet, digit, or special character; Through this tutorial, we will learn how to check whether the character is alphabet, digit, or special character.

  • C Program to Check Character is Alphabet, Digit or Special Character using if else
  • C Program to Check Character is Alphabet, Digit or Special Character using Ascii value
  • C Program to Check Character is Alphabet, Digit or Special Character Function

C Program to Check Character is Alphabet, Digit or Special Character using if else

/* C Program to check Character is Alphabet Digit or Special Character */ #include <stdio.h> int main() { char ch; printf(" Please Enter any character : "); scanf("%c", &ch); if( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ) { printf("\n %c is an Alphabet", ch); } else if (ch >= '0' && ch <= '9') { printf("\n %c is a Digit", ch); } else printf("\n %c is a Special Character", ch); return 0; }

The output above c program; as follows:

Please Enter any character : 5 5 is a Digit

C Program to Check Character is Alphabet, Digit or Special Character using Ascii value

#include <stdio.h> int main() { char ch; printf(" Please Enter any character : "); scanf("%c", &ch); if (ch >= 48 && ch <= 57) { printf("\n %c is a Digit", ch); } else if ( (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) ) { printf("\n %c is an Alphabet", ch); } else printf("\n %c is a Special Character", ch); return 0; }

The output above c program; as follows:

Please Enter any character : $ $ is a Special Character

C Program to Check Character is Alphabet, Digit or Special Character using Function

/* C Program to check Character is Alphabet Digit or Special Character */ #include <stdio.h> #include<ctype.h> int main() { char ch; printf(" Please Enter any character : "); scanf("%c", &ch); if (isalpha(ch)) { printf("\n %c is an Alphabet", ch); } else if (isdigit(ch)) { printf("\n %c is a Digit", ch); } else printf("\n %c is a Special Character", ch); return 0; }

The output above c program; as follows:

Please Enter any character : w w is an Alphabet