Example
Input
Input alphabet: c
Output
'c' is consonant
/**
* C program to check vowel or consonant using switch case
*/
#include <stdio.h>
int main()
{
char ch;
/* Input an alphabet from user */
printf("Enter any alphabet: ");
scanf("%c", &ch);
/* Switch value of ch */
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
/*
Output :
Enter any alphabet: E
VOWEL
*/
Another approach:
/**
* C program to check vowel or consonant using switch case
*/
#include <stdio.h>
int main()
{
char ch;
/* Input alphabet from user */
printf("Enter any character: ");
scanf("%c", &ch);
/* Switch ch value */
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("Vowel");
break;
default: printf("Consonant");
}
return 0;
}
/*
Output :
Enter any alphabet: E
VOWEL
*/