C program to find whether a given character is an alphabet,digit or any special character(using ASCII values)

#include<stdio.h>
#include<conio.h>

void main()
{
    char ch;
    clrscr();    //to clear the screen
    printf(“Enter any character:”);
    scanf(“%c”,&ch);

    if((ch>=’A’&&ch<=’Z’)||(ch>=’a’&&ch<=’z’))
        printf(“nYou have entered an alphabet”);
    else
        if(ch>=’0’&&ch<=’9′)
            printf(“nYou have entered a digit”);
        else
            printf(“nYou have entered a special character”);

    getch();    //to stop the screen
}

10 thoughts on “C program to find whether a given character is an alphabet,digit or any special character(using ASCII values)”

  1. /* smaller code 🙂 */

    #include

    int main()
    {
    char a;

    printf("Please input a character: ");
    scanf("%c", &a);

    (a >= 'a' && a <= 'z' || a>='A' && a<='Z' || a>='0'&& a<= '9' ? printf("character is not special") : printf("character is special") );

    getch();/* not to use if making prog in command line directly using devc++ */

    }

  2. if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
    what will happen if we don't add parentheses for each expression on either sides of the logical or operator ?!
    pls help 🙂

  3. We are adding parenthesis to ensure any kind of confusion, otherwise the expression will be executed according to operator precedence and this will cause undesired results. This also make the expression easy to understand. 🙂

    1. How to write a program to check whether the given input is alphabet, number or special character using (switch case)? Please teach me 🙁

Leave a Comment

Your email address will not be published. Required fields are marked *