C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Check whether a character is alphabet or not

Introduction

In C programming, characters can be classified as alphabets, digits, or special symbols.
An alphabet is any character from A–Z or a–z.

We can check this using:

  • ASCII values (65–90 for A–Z and 97–122 for a–z)
  • or using relational operators in C (if (ch >= 'A' && ch <= 'Z'))

C Program: Check Whether a Character is an Alphabet or Not

C

#include <stdio.h>

 

int main() {

    char ch;

 

    // Input a character

    printf("Enter a character: ");

    scanf("%c", &ch);

 

    // Check whether it is an alphabet

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

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

    } else {

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

    }

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter a character: A
A is an alphabet.

OUTPUT 2 :
Enter a character: 9
9 is not an alphabet.

OUTPUT 3 :
Enter a character: $
$ is not an alphabet.

Explanation

  1. User enters a single character.
  2. Program checks:
    • If it lies between 'A' and 'Z' (uppercase alphabets)
    • OR between 'a' and 'z' (lowercase alphabets)
  3. If condition is true → it's an alphabet; else → not an alphabet.