Write a C program to Check alphabet character

Topics

  • In this program, we first declare a variable c of type char to store the input character. We then prompt the user to enter a character using the printf() and scanf() functions.
  • Next, we use an if-else statement to check if the entered character is an alphabet or not. The condition for an alphabet character is that it should lie between ‘a’ and ‘z’ (lowercase) or ‘A’ and ‘Z’ (uppercase). If the condition is true, the program outputs a message saying that the character is an alphabet. Otherwise, the program outputs a message saying that the character is not an alphabet.
  • Finally, the program returns 0 to indicate that it has executed successfully.
#include <stdio.h>

int main() {
    char c;

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

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

    return 0;
}

OUTPUT

Enter a character: d
d is an alphabet.


Related Posts

Leave a Reply

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