C program to check if a character is uppercase or lowercase alphabet


C program distinguishing between uppercase and lowercase characters using ASCII values and conditional checks. Enhance your C programming skills with this tutorial.

In this article, we'll explore how to create a simple C program to check whether a given character is an uppercase or lowercase alphabet.

Understanding Uppercase and Lowercase Alphabets

In the English alphabet, characters from 'A' to 'Z' are considered uppercase, and characters from 'a' to 'z' are considered lowercase.

C program to check if a character is uppercase or lowercase alphabet

Let's delve into the C programming language to create a program that determines whether a user-input character is an uppercase or lowercase alphabet.

#include <stdio.h>

int main() {
    char ch;

    // Input from the user
    printf("Enter an alphabet: ");
    scanf(" %c", &ch);

    // Checking if the character is uppercase or lowercase
    if (ch >= 'A' && ch <= 'Z') {
        printf("%c is an Uppercase Alphabet.\\n", ch);
    } else if (ch >= 'a' && ch <= 'z') {
        printf("%c is a Lowercase Alphabet.\\n", ch);
    } else {
        printf("%c is not an Alphabet.\\n", ch);
    }

    return 0;
}

Output

Enter an alphabet: C
C is an Uppercase Alphabet.

Uppercase or Lowercase Check: The program checks if the entered character falls within the ASCII range of uppercase or lowercase alphabets and identifies the character accordingly.

In this article, we've created a simple C program that efficiently determines whether a given character is an uppercase or lowercase alphabet. Understanding ASCII values and utilizing conditional checks in C allows us to accurately classify characters based on their cases.


Recommended Posts