write a c program to tell whether a given character is an alphabet,numer or a special carecter.
Answers
A character is alphabet if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) . Next, check condition for digits. A character is digit if(ch >= '0' && ch <= '9') . Finally, if a character is neither alphabet nor digit, then character is a special character.
Answer:
cial character
/**
* C program to check alphabet, digit or special character
*/
#include <stdio.h>
int main()
{
char ch;
/* Input character from user */
printf("Enter any character: ");
scanf("%c", &ch);
/* Alphabet check */
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
Example
Input
Input any character: 3
Output
3 is digit