Program to Check Whether Character is Lowercase or Not without using islower function
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
if (c >= 'a' && c <= 'z') {
printf("The character is lowercase.\n");
} else {
printf("The character is not lowercase.\n");
}
return 0;
}
Explanation:
1. We include the <stdio.h>
header file, which allows us to use input/output functions like printf
and scanf
.
2. We declare the main
function, which is the entry point of the program.
3. We declare a variable c
of type char
to store the character.
4. We prompt the user to enter a character using printf
and scanf
. The %c
format specifier is used to read a character input from the user and store it in the variable c
.
5. We use an if
statement to check if the character is lowercase. The condition c >= 'a' && c <= 'z'
checks if the ASCII value of the character is between the ASCII values of lowercase 'a' and lowercase 'z'. If the condition is true, the character is lowercase.
6. If the character is lowercase, we print the message "The character is lowercase" using printf
.
7. If the character is not lowercase, we print the message "The character is not lowercase" using printf
.
8. Finally, we return 0 to indicate successful program execution to the operating system.