c
  1. c-program-to-check-whether-a-character-is-an-alphabet-or-not

Program to Check Whether a Character is an Alphabet or Not - (C Programs)

Example

#include <stdio.h>

int main() {
    char ch;

    printf("Enter a character: ");
    scanf("%c", &ch);

    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
        printf("%c is an alphabet.", ch);
    else
        printf("%c is not an alphabet.", ch);
    
    return 0;
}

Output

Enter a character: 9
9 is not an alphabet.

Explanation

In this program, we take input from the user in the form of a character. We then use an if-else statement to determine whether the character is an alphabet or not.

The condition for the if statement checks whether the character is a lowercase or uppercase letter in the English alphabet. If the character meets either of these conditions, it's considered an alphabet. If it doesn't meet both conditions, the program outputs that it's not an alphabet.

Use

This program can be useful in situations where you want to check whether a character entered by a user or obtained by some other means is a letter of the alphabet or not. It could be used in applications that require password generation or text processing.

Summary

This program takes a character as input and checks whether it's an alphabet or not. It does this by checking whether the character is a lowercase or uppercase letter in the English alphabet. If it's an alphabet, it outputs the character as such. If not, it outputs that the character is not an alphabet.

Published on: