A, E, I, O
and U
are called vowels. All other alphabets except these 5 vowels
are called consonants.#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
// evaluates to 1 if variable c is a lowercase vowel
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is a uppercase vowel
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 (true) if c is a vowel
if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
Enter an alphabet: U
U is a vowel.
c
.lowercase_vowel
variable evaluates to 1 (true) if c is a lowercase vowel
and 0 (false) for any other characters.uppercase_vowel
variable evaluates to 1 (true) if c is an uppercase vowel
and 0 (false) for any other character.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.isalpha()
function. The islapha()
function checks whether a character is an alphabet or not.#include <ctype.h>
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
// evaluates to 1 if variable c is a lowercase vowel
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is a uppercase vowel
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// Show error message if c is not an alphabet
if (!isalpha(c))
printf("Error! Non-alphabetic character.");
else if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
Enter an alphabet: 7
Error! Non-alphabetic character.