Home >>c programs >c program to check vowel or consonant using switch

c program to check vowel or consonant using switch

WAP in c to check vowel and cosonent using switch

A user inputs a character, and we check whether it’s a vowel or not using switch case statement. The alphabets ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ (both lowercase and uppercase) are known as vowels. Alphabets except vowels are known as consonants.

Let's take an example :

#include<stdio.h>    
int main()
{    
char c;    
printf("Please enter any single character:");  
scanf("%s",&c); 
if(c=='a')
{
printf("its vowel");    
}
else if (c=='e')
{
printf("its vowel");
}
else if (c=='i')
{
printf("its vowel");
}
else if (c=='o')
{
printf("its vowel");
}
else if (c=='u')
{
printf("its vowel");
}
else
{
    printf("its consonant");
}
return 0;  
}    
Output :
Please enter any single character:a
its vowel
Output :
Please enter any single character:b
its consonant

Using Switch Case

By using switch case we also check that the inputs character is vowel or not.

Let's take an example :

#include<stdio.h>    
int main()
{    
char c;    
printf("Please enter any single character:");  
scanf("%s",&c); 
switch(c)
{
case 'a':
printf("a is  vowel");
break;
case 'e':
printf("e is  vowel");
break;
case 'i':
printf("i is  vowel");
break;
case 'o':
printf("o is  vowel");
break;
case 'u':
printf("u is  vowel");
break;
default:
printf("its consonant");
}
return 0;  
}    
Output :
Please enter any single character:i
i is vowel
Output :
Please enter any single character:b
its consonant

No Sidebar ads