Write a C program to check whether a character is uppercase or lowercase.
#include <stdio.h>
int main() {
int ch;
printf("Enter your input character:");
ch = getchar();
/* checking whether input character is uppercase */
if (ch >= 'A' && ch <= 'Z') {
printf("%c is an uppercase character\n", ch);
} else if (ch >= 'a' && ch <= 'z') {
/* input character is lowercase */
printf("%c is a lowercase character\n", ch);
} else {
/* input character is not an alphabet */
printf("%c is not an alphabet\n", ch);
}
return 0;
}
int main() {
int ch;
printf("Enter your input character:");
ch = getchar();
/* checking whether input character is uppercase */
if (ch >= 'A' && ch <= 'Z') {
printf("%c is an uppercase character\n", ch);
} else if (ch >= 'a' && ch <= 'z') {
/* input character is lowercase */
printf("%c is a lowercase character\n", ch);
} else {
/* input character is not an alphabet */
printf("%c is not an alphabet\n", ch);
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:Z
Z is an uppercase character
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:3
3 is not an alphabet
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:a
a is a lowercase character
Enter your input character:Z
Z is an uppercase character
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:3
3 is not an alphabet
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:a
a is a lowercase character
No comments:
Post a Comment