by Dinesh Thakur Category: C Programming (Pratical)

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


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.