Write a C Program to Check the Character is Lowercase or Uppercase Alphabet using built-in functions and ASCII codes.
C Program to Check the Character is Lowercase or Uppercase Alphabet
This program allows the user to enter any character and check whether the character is an uppercase alphabet or not using built-in functions isupper, and islower
In C Programming, there are built-in functions in <ctype.h> header file called isupper and islower. You can use these functions to check whether the character is a lowercase alphabet or uppercase alphabet.
#include<stdio.h>
#include<ctype.h>
int main()
{
char Ch;
printf("\n Please Enter any alphabet : ");
scanf("%c", &Ch);
if ( islower(Ch) )
{
printf ("\n Entered character is a Lowercase Alphabet");
}
else if ( isupper(Ch) )
{
printf ("\n Entered character is an Uppercase Alphabet");
}
else
{
printf("\n Entered character is Not an Alphabet");
}
return 0;
}
Please Enter any alphabet : T
Entered character is an Uppercase Alphabet
OUTPUT 2
Please Enter any alphabet : g
Entered character is a Lowercase Alphabet
3rd OUTPUT
Please Enter any alphabet : 9
Entered character is Not an Alphabet
Program to Check the Character is Lowercase or Uppercase Alphabet Example 2
In this program, we are not using isupper or islower function. Instead of them, we are directly placing alphabets inside the If Statement.
#include<stdio.h>
int main()
{
char Ch;
printf("\n Please Enter any alphabet\n");
scanf("%c", &Ch);
if (Ch >= 'a' && Ch <= 'z')
{
printf ( "\n Entered character is a Lowercase Alphabet") ;
}
else if (Ch >= 'A' && Ch <= 'Z')
{
printf ( "\n Entered character is an Uppercase Alphabet") ;
}
else
{
printf("\n Entered character is Not an Alphabet");
}
return 0;
}
Please Enter any alphabet
k
Entered character is a Lowercase Alphabet
Let us check with a false value
Please Enter any alphabet
@
Entered character is Not an Alphabet
Program to Check the Character is Lowercase or Uppercase Alphabet Example 3
In this program, we are using the ASCII Table codes to check whether the Character is an Uppercase alphabet or lowercase.
#include<stdio.h>
int main()
{
char Ch;
printf("\n Please Enter any alphabet\n");
scanf("%c", &Ch);
if (Ch >= 65 && Ch <= 90)
{
printf ( "\n Entered character is an Uppercase Alphabet") ;
}
else if (Ch >= 97 && Ch <= 122)
{
printf ( "\n Entered character is a Lowercase Alphabet") ;
}
else
{
printf("\n Entered character is Not an Alphabet");
}
return 0;
}