C program to check a character is an alphabet, digit or special character
Q:-Write a C program to check a character is an alphabet, digit or special character.
In this section, we will see how to check whether a given character is number, or the alphabet or some special character in C.
The alphabets are from A – Z and a – z, Then the numbers are from 0 – 9. And all other characters are special characters. So If we check the conditions using these criteria, we can easily find them.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\nEnter Any Character :");
scanf("%c",&ch);
if(ch>='0' && ch<='9')
{
printf("\n Entered Character is Digit");
}
else if(ch>='A' && ch<='Z')
{
printf("\n Entered Character is Capital Letter");
}
else if(ch>='a' && ch<='z')
{
printf("\n Entered Character is Small Letter");
}
else
{
printf("\n Entered Character is Special Character");
}
getch();
}