Write a C program to check whether the given input is alphabet or not.
int main() {
int ch;
/* get the input character from the user */
printf("Enter your input character:");
ch = getchar();
/*
* if the input character is not from a to z or
* A to Z then the input character is alphabet.
* Otherwise not an alphabet.
*/
if ((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z')) {
printf("Given input %c is a character\n", ch);
} else {
printf("Given input %c is not a character\n", ch);
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:Z
Given input Z is a character
Enter your input character:Z
Given input Z is a character
No comments:
Post a Comment