C Program to Check Whether Character is Lowercase or Not using islower function
The C program below checks whether a given character is lowercase or not using the islower
function:
#include <ctype.h>
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (islower(ch)) {
printf("The character is lowercase.\n");
} else {
printf("The character is not lowercase.\n");
}
return 0;
}
Explanation of the steps:
1. Include the necessary header files: ctype.h
for the islower
function and stdio.h
for standard input/output functions.
2. Declare a variable ch
of type char
to store the input character.
3. Prompt the user to enter a character using the printf
function.
4. Read the character entered by the user using the scanf
function and store it in the variable ch
.
5. Use the islower
function to check if the character is lowercase. The islower
function returns a non-zero value if the character is lowercase, and 0 otherwise.
6. Use an if
statement to check the return value of the islower
function. If it is non-zero, print that the character is lowercase. Otherwise, print that the character is not lowercase.
7. Finally, return 0 from the main
function to indicate successful execution of the program.
This program uses the islower
function from the ctype.h
header file to check if a character is lowercase or not. The function takes a single argument, which is the character to be checked. It returns a non-zero value if the character is lowercase and 0 otherwise. By using an if
statement, the program determines whether to print that the character is lowercase or not based on the return value of the islower
function.