C code to check a character is a vowel or consonant
Character is a vowel or consonant in C
Here, in this section we will discuss the program to check whether the character is a vowel or consonant in C. In this program we take a character from the user then check that entered character. A character is said to be a vowel if it is one of the five following alphabet – a, e, i, o, u. All the remaining alphabets are called consonants i.e. b, c, d, f, g, h, i, j, k, l, m, n etc are the consonants.
Now in here we will see how we can identify whether a character is a vowel or consonant using the C programming language.
Example : Input => i
Output => i is a vowel
Input => T
Output => T is a consonant
We check whether given character matches any of the 5 vowels. If yes, we print “Vowel”, else we print “Consonant”.
- This C program allows the user to enter any character and check whether the user specified character is Vowel or Consonant using If Else Statement.
- This program takes the character value(entered by user) as input.
- And checks whether that character is a vowel or consonant using if-else statement.
- Since a user is allowed to enter an alphabet in lowercase and uppercase, the program checks for both uppercase and lowercase vowels and consonants.
- And now we have to follow step’s of C programming
C program to check whether a character is a vowel or consonant:-
int isLowerVowel, isUpperVowel;
printf("Enter an alphabet: ");
//To find the corrector is lowercase vowel
isLowerVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
//To find the character is Upper case vowel
isUpperVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// compare to charector is Lowercase Vowel or Upper case Vowel
if (isLowerVowel || isUpperVowel)
printf("%c is a vowel", c);
//to check character is alphabet or not
else if(!((c >= 'a' && c <='z') || (c >= 'A' && c <= 'Z')))
printf("%c not a alphabet", c);
printf("%c is a consonant", c);
output: Enter an alphabet: d d i the consonant Enter an alphabet: a a is vowel