C Program to Check Whether a Character is Vowel or Consonant

C Program to Check Whether a Character is Vowel or Consonant

The five alphabets A, E, I, O and U are called vowels. All other alphabets except these 5 vowel letters are called consonants.

 

#include <stdio.h>
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;

printf(“Enter an alphabet: “);
scanf(“%c”,&c);

// evaluates to 1 (true) if c is a lowercase vowel
isLowercaseVowel = (c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’);

// evaluates to 1 (true) if c is an uppercase vowel
isUppercaseVowel = (c == ‘A’ || c == ‘E’ || c == ‘I’ || c == ‘O’ || c == ‘U’);

// evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true
if (isLowercaseVowel || isUppercaseVowel)
printf(“%c is a vowel.”, c);
else
printf(“%c is a consonant.”, c);
return 0;
}

 

Output

Enter an alphabet: G
G is a consonant.