A Program to Check a Character is Vowel or Consonant

In this example, we are giving a program which is useful to check whether a character given by the user is vowel or consonant.


Program to check Vowel or Consonant:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. char c;
  5. int isLowercaseVowel, isUppercaseVowel;
  6. printf("Enter an alphabet: ");
  7. scanf("%c",&c);
  8. // true if c is a lowercase vowel
  9. isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
  10. // true if c is an uppercase vowel
  11. isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
  12. // true if either isLowercaseVowel or isUppercaseVowel is true
  13. if (isLowercaseVowel || isUppercaseVowel)
  14. printf("%c is a vowel.", c);
  15. else
  16. printf("%c is a consonant.", c);
  17. return 0;
  18. }

Output:

Enter a character: E
E is a vowel.