Write a C program to input character from user and check whether character is uppercase or lowercase alphabet using if else. How to check uppercase and lowercase using if else in C programming. Logic to check uppercase and lowercase alphabets in C program.
Input
Input character: C
Output
'C' is uppercase alphabet
Required knowledge
Basic C programming, Relational operators, Logical operators, If else
Logic to check uppercase and lowercase alphabets
Step by step descriptive logic to check uppercase and lowercase alphabets.
- Input a character from user. Store it in some variable say ch.
- Character is uppercase alphabet
if(ch >= 'A' and ch <= 'Z')
. - Character is lowercase alphabet
if(ch >= 'a' and ch <= 'z')
. - If none of the above conditions met, then character is not alphabet.
Program to check uppercase or lowercase alphabets
You can also use inbuilt library function isupper()
and islower()
to check uppercase and lowercase alphabets respectively. These functions are present in ctype.h
header file. Both function returns 1 if given character is uppercase or lowercase respectively otherwise returns 0.
Program to check uppercase or lowercase characters using library functions
The statement if(isupper(ch))
is equivalent to if(isupper(ch) == 1)
.
Output
Enter any character: C 'C' is uppercase alphabet.
Happy coding
You may also like
- If else programming exercises and solutions.
- C program to convert uppercase string to lowercase.
- C program to convert lowercase string to uppercase.
- C program to check whether a character is alphabet or not.
- C program to check whether a character is vowel or consonant.
- C program to check whether a character is alphabet, digit or any special character.