C Program to Check Whether an Alphabet is Vowel or Consonant Using Switch Case
In this tutorial, we are going to see how to write a C program to check whether an alphabet is a vowel or consonant using Switch Case. There are six alphabets (A, E, I, O, U, and Y) are called vowels. All the remaining alphabets except these five are called consonants. There are three ways to check whether an alphabet is a vowel or consonant, by using if-else, switch-case, or by function.
C Program to Check Whether an Alphabet is Vowel or Consonant Using Switch Case
#include <stdio.h> int main() { char c; printf("Enter a character: "); scanf("%c",&c); //Check if it's alphabet or not if((c>='A' && c<='Z') || (c>='a' && c<='z')) { //check if it's vowel or consonant switch(c) { case 'A': case 'E': case 'I': case 'O': case 'U': case 'a': case 'e': case 'i': case 'o': case 'u': printf("%c is a vowel.\n",c); break; default: printf("%c is a consonant.\n",c); } } else { printf("%c is not an alphabet.\n",c); } return 0; }
Output:
Enter a character: a a is a vowel.