You can use isalpha()
to see if a character is a letter or not. And you can cut the number of case
statements you use by converting the character into lowercase using tolower()
, which makes the code simpler and less likely you’d miss something.
if(isalpha(ch)) {
switch(tolower(ch)) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("Vowel");
break;
default:
printf("Consonant");
break;
}
} else {
printf("Invalid");
}
4
solved to write a c program using switch case to find whether a character is vowel or consonant