The five letters A, E, I, O and U are called vowels. All other alphabets except these 5 vowels are called consonants.
This program assumes that the user will always enter an alphabet character.
Program to Check Vowel or consonant
Output
Enter an alphabet: G G is a consonant.
The character entered by the user is stored in variable c.
The lowercase_vowel variable evaluates to 1 (true) if c is a lowercase vowel and 0 (false) for any other characters.
Similarly, the uppercase_vowel variable evaluates to 1 (true) if c is an uppercase vowel and 0 (false) for any other character.
If either lowercase_vowel or uppercase_vowel variable is 1 (true), the entered character is a vowel. However, if both lowercase_vowel and uppercase_vowel variables are 0, the entered character is a consonant.
Note: This program assumes that the user will enter an alphabet. If the user enters a non-alphabetic character, it displays the character is a consonant.
To fix this, we can use the isalpha() function. The islapha() function checks whether a character is an alphabet or not.
Now, if the user enters a non-alphabetic character, you will see:
Enter an alphabet: 3 Error! Non-alphabetic character.