Skip to content
Home » Check Character is Vowel or Consonant using Switch case

Check Character is Vowel or Consonant using Switch case

Learn about Check Character is Vowel or Consonant using Switch case in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Check Character is Vowel or Consonant using Switch case

Source code:

#include<stdio.h>
int main()
{
   char ch;
   char uppercase, lowercase;
   int result;

   printf("Enter any character: ");
   scanf("%c",&ch);

   uppercase = (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U');
   lowercase = (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
   result = ( uppercase||lowercase );

   switch(result)
   {
   case 1:
     printf("Vowel\n");
     break;
   case 0:
     printf("Consonant\n");
     break;
   default:
     printf("Invalid character\n");
     break;
   }

   return 0;
}

Output:

Enter any character: k
Consonant

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to check vowel or consonant Using If-else
Absolute value in C without using the predefined function