- In this program, we first declare a variable
c
of data type char
. We then prompt the user to enter a character using the printf
and scanf
functions. - Next, we use a series of
if-else
statements to determine if the entered character is an uppercase or lowercase letter. The first condition checks if the character is an uppercase letter by checking if it falls within the ASCII range for uppercase letters. If the character is an uppercase letter, the program prints the message “c is an uppercase letter.”. - If the character is not an uppercase letter, the next condition checks if it is a lowercase letter by checking if it falls within the ASCII range for lowercase letters. If the character is a lowercase letter, the program prints the message “c is a lowercase letter.”.
- Finally, if the character is neither an uppercase nor a lowercase letter, it is assumed to be a non-letter character and the program prints the message “c is not a letter.”.
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
if (c >= 'A' && c <= 'Z') {
printf("%c is an uppercase letter.", c);
}
else if (c >= 'a' && c <= 'z') {
printf("%c is a lowercase letter.", c);
}
else {
printf("%c is not a letter.", c);
}
return 0;
}
OUTPUT
Enter a character: A
A is an uppercase letter.
Enter a character: b
b is a lowercase letter.
Enter a character: #
# is not a letter.