C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether a character is a digit or special character

Introduction

In C programming, characters fall into one of these categories:

  • Alphabet: A–Z or a–z
  • Digit: 0–9
  • Special Character: Any other printable character (e.g., @, #, $, etc.)

We can determine the type of character using conditional statements and ASCII value ranges.

 

C Program: Check whether a character is a digit or special character

C

#include <stdio.h>

 

int main() {

    char ch;

 

    // Input character

    printf("Enter a character: ");

    scanf("%c", &ch);

 

    // Check type of character

    if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {

        printf("%c is an Alphabet.\n", ch);

    }

    else if (ch >= '0' && ch <= '9') {

        printf("%c is a Digit.\n", ch);

    }

    else {

        printf("%c is a Special Character.\n", ch);

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter a character: G
G is an Alphabet.

OUTPUT 2 :
Enter a character: 7
7 is a Digit.

OUTPUT 3 :
Enter a character: @
@ is a Special Character.

Explanation

  1. Program accepts a single character from the user.
  2. It checks:
    • If character is between A–Z or a–z → Alphabet
    • Else if character is between 0–9 → Digit
    • Else → Special Character
  3. The result is displayed accordingly.