Identifying Uppercase and Lowercase Characters in C

#include <stdio.h>

int main() {
    char a; // Variable to store the input character
   
    printf("Enter a character:"); // Prompt the user to enter a character
    scanf("%c", &a); // Read the character input from the user
   
    if (a >= 97 && a <= 122) { // Check if the character is a lowercase alphabet (ASCII values for 'a' to 'z' are 97 to 122)
        printf("It is a lowercase alphabet");
    }
    else if (a >= 65 && a <= 90) { // Check if the character is an uppercase alphabet (ASCII values for 'A' to 'Z' are 65 to 90)
        printf("It is an uppercase character");
    }
    else { // If the character is neither uppercase nor lowercase, it is not an alphabet
        printf("It is not an alphabet");
    }
    return 0;
}

Comments

Popular posts from this blog

Weird Algorithm || Introductory Problem || CSES