This program checks whether the character (entered by user) is an alphabet or not.
Example: Program to check if a character is an Alphabet or not
This program takes the character value (entered by user) and checks whether it lies between the following ranges:
For lowercase alphabets: >= ‘a’ and <= ‘z’
For uppercase alphabets: >= ‘A’ and <= ‘Z’
If the input character lies in one of these ranges then the character is an alphabet else it’s not an alphabet. To understand this program, you should have the knowledge of following C programming topic:
#include <stdio.h> int main() { char ch; //Asking user to enter the character printf("Enter any character: "); //storing the entered character into the variable ch scanf("%c",&ch); if( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z')) printf("The entered character %c is an Alphabet",ch); else printf("The entered character %c is not an Alphabet",ch); return 0; }
Output 1:
Enter any character: 9 The entered character 9 is not an Alphabet
Output 2:
Enter any character: P The entered character P is an Alphabet
You can also check the alphabet using the ASCII values of characters like this:
if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90)) printf("The entered character %c is an Alphabet",ch); else printf("The entered character %c is not an Alphabet",ch);
The ASCII value of ‘a’ is 97, ‘z’ is 122, ‘A’ is 65 and ‘Z’ is 90.
Check out these related programs:
Leave a Reply