C program to check whether a character is Uppercase or Lowercase

Write a C program to check whether a character is uppercase or lowercase alphabet using if else . How to check uppercase and lowercase using if else in C programming. Program to enter a character from user and check whether the character is uppercase or lowercase alphabet without using in built library function. Logic to check uppercase and lowercase alphabets in C program.

Example
Input

Input character: C

Output

C is uppercase alphabet

Required knowledge

Basic C programming, If else

Logic to check uppercase and lowercase alphabets

If you are following my previous posts then you probably know the logic of this program. In previous posts I already explained logic for lower and uppercase alphabets. Let us recall the definitions for lowercase and uppercase alphabets once again.

  • Lowercase alphabets are the characters in between a-z (ASCII 97-122).
  • Uppercase alphabets are the character in between A-Z (ASCII 65-90).

Read more - List of ASCII character values.

Using the above definition we can write step by step descriptive logic.

  1. Input a character from user and store it in some variable say ch.
  2. Check condition for uppercase alphabets i.e. if ch >= 'A' and ch <= 'Z'. Then the given character is uppercase alphabet.
  3. Check condition for lowercase alphabets i.e. if ch >= 'a' and ch <= 'z'. Then the given character is lowercase alphabet.

Program to check uppercase or lowercase alphabets

/**
 * C program to check whether a character is uppercase or lowercase 
 */

#include <stdio.h>

int main()
{
    char ch;

    /* Input character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);


    if(ch >= 'A' && ch <= 'Z')
    {
        printf("%c is uppercase alphabet.", ch);
    }
    else if(ch >= 'a' && ch <= 'z')
    {
        printf("%c is lowercase alphabet.", ch);
    }
    else
    {
        printf("%c is not an alphabet.", ch);
    }

    return 0;
}

You can also use inbuilt library function isupper() and islower() to check whether a character is uppercase or lowercase respectively. These functions are present in ctype.h header file. Both the functions returns 1 if the given character is uppercase or lowercase respectively otherwise returns 0.

Program to check uppercase or lowercase characters using library functions

/**
 * C program to check whether a character is uppercase 
 * or lowercase using inbuilt library functions
 */

#include <stdio.h>
#include <ctype.h> //Used for isupper() and islower()

int main()
{
    char ch;

    /* Input a character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);

    if(isupper(ch))
    {
        printf("%c is uppercase alphabet.", ch);
    }
    else if(islower(ch))
    {
        printf("%c is lowercase alphabet.", ch);
    }
    else
    {
        printf("%c is not an alphabet.", ch);
    }

    return 0;
}

Output

Enter any character: C
C is uppercase alphabet.

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>