In this program we are going to see whether a user given character is alphabet or not. To determine the type of character, we have to check it’s ASCII value range.
See also: Find ASCII value of a character
Logic
To check if it is a alphabet or not we only need to check its ASCII value range. If it is a alphabet then it’s ASCII value range should be within 65 (A) – 90 (Z) or 97 (a) – 122 (z).
Program
#include <stdio.h> int main() { char c; printf("Enter any character : "); scanf("%c", &c); if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { printf("\n%c is ALPHABET.\n", c); } else { printf("\n%c is NOT ALPHABET.\n", c); } return 0; }
Output
Enter any character : x
x is ALPHABET.