Check if character is lowercase or uppercase in C

This C program reads a character from the user and checks if it is a lowercase letter from 'a' to 'z'. If so, it prints 'Lowercase'. It begins to structure the logic for uppercase letters too but doesn't complete it.
mail@pastecode.io avatar
unknown
c_cpp
5 months ago
1.7 kB
1
Indexable
#include <stdio.h>

int main() {
    char ch;
    scanf("%c", &ch);
    if (
             ch == 'a' ||  
             ch == 'b' ||  
             ch == 'c' ||  
             ch == 'd' ||  
             ch == 'e' ||  
             ch == 'f' || 
             ch == 'g' ||
             ch == 'h' ||
             ch == 'i' ||  
             ch == 'j' ||  
             ch == 'k' ||  
             ch == 'l' ||  
             ch == 'm' ||  
             ch == 'n' ||  
             ch == 'o' ||  
             ch == 'p' ||  
             ch == 'q' ||  
             ch == 'r' ||  
             ch == 's' ||  
             ch == 't' ||  
             ch == 'u' ||  
             ch == 'v' ||  
             ch == 'w' ||  
             ch == 'x' ||  
             ch == 'y' ||  
             ch == 'z'
        ) {
            printf("Lowercase");
        } else if (
             ch == 'A' ||  
             ch == 'B' ||  
             ch == 'C' ||  
             ch == 'D' ||  
             ch == 'E' ||  
             ch == 'F' ||  
             ch == 'G' ||  
             ch == 'H' ||  
             ch == 'I' ||  
             ch == 'J' ||  
             ch == 'K' ||  
             ch == 'L' ||  
             ch == 'M' ||  
             ch == 'N' ||  
             ch == 'O' ||  
             ch == 'P' ||  
             ch == 'Q' ||  
             ch == 'R' ||  
             ch == 'S' ||  
             ch == 'T' ||  
             ch == 'U' ||  
             ch == 'V' ||  
             ch == 'W' ||  
             ch == 'X' ||
             ch == 'Y' ||
             ch == 'Z'
            ) {
                printf("Uppercase");
            } else {
                printf("Wrong value entered");
            }

    return 0;
}
Leave a Comment