by Dinesh Thakur

A given character is a vowel if it is one of the following characters: A, E, I, O and U. The switch case given below tests whether a given character is a vowel or not.

Note that we have to compare variable ch with uppercase as well as lowercase letters. We can reduce the number of comparisons in the above code if we first convert the given character to uppercase (or lowercase) representation. Thus, the condition in the switch involves comparison with uppercase (or lowercase) letters only. The code using this approach is given below.


#include<stdio.h>

void main()
{
         char a;
         clrscr();
         printf("Enter any Alphabet : ");
         scanf("%ch",&a);
         switch (a)
              {
                  case'A':
                  case'a':
                  case'E':
                  case'e':
                  case'I':
                  case'i':
                  case'O':
                  case'o':
                  case'U':
                  case'u':
                                 printf("It is a Vowel");
                                 break;
                  default:
                                 printf("It is a Consonent");
}
                                 getch();
}
Output :
Enter any Alphabet : i
It is a Vowel