Algorithm
a and A both are different and have different ASCII values.
Step by step descriptive logic to check alphabets.
- Input a character from user. Store it in some variable say ch.
- Check
if((ch >= 'a') && (ch <= 'z'))
orif((ch >= 'A') && (ch <= 'Z'))
. - Then it is alphabet otherwise not.
Code Examples
#1 Code Example-C Program to check alphabets
Code -
C Programming
/**
* C program to check whether a character is alphabet or not
*/
#include <stdio.h>
int main()
{
char ch;
/* Input a character from user */
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch lt;= 'z') || (ch >= 'A' && ch lt;= 'Z'))
{
printf("Character is an ALPHABET.");
}
else
{
printf("Character is NOT ALPHABET.");
}
return 0;
}
Copy The Code &
Try With Live Editor
Output
Enter any character: b
Character is an ALPHABET.
Character is an ALPHABET.
#2 Code Exampl-C Programing to check alphabets using ASCII value
Code -
C Programming
/**
* C program to check whether a character is alphabet or not
*/
#include <stdio.h>
int main()
{
char ch;
/* Input a character from user */
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
{
printf("Character is an ALPHABET.");
}
else
{
printf("Character is NOT ALPHABET.");
}
return 0;
}
Copy The Code &
Try With Live Editor
Demonstration
C Programing Example to Check Whether a Character is an Alphabet or not-DevsEnv