C Program To Check if Character is Vowel or Not
Learn How To Check if Character is Vowel or Not in C Programming. This Program makes use of If Else Block and Switch Case to Find if the Entered Character is a Vowel or a Consonant. This program compares the characters with Vowels using ASCII Values.
Method 1: C Program To Check if Entered Character is Vowel or Consonant using If Else
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<stdio.h> int main() { char ch; printf("\nEnter A Character:\t"); scanf("%c", &ch); if((ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') ||(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' )) { printf("\n%c is a Vowel\n", ch); } else { printf("\n%c is a Consonant\n", ch); } return 0; } |
Method 2: C Program To Find if Character is Vowel or Not using Switch Case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<stdio.h> int main() { char ch; printf("\nEnter A Character:\t"); scanf("%c", &ch); switch(ch) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'A': case 'E': case 'I': case 'O': case 'U': printf("\n%c is a Vowel\n", ch); break; default: printf("\n%c is a Consonant\n", ch); } return 0; } |
Output

If you have any compilation error or doubts in this C Program to Find if the Character is a Vowel or Not, let us know about it in the Comment Section below.
I think the If Else Block is much more easier than Switch case as we can enlist all the vowels in a single statement.
If you like If Else, its perfectly fine. But, you must also understand how switch statement works!
This is a new type of working of Switch case. I had not seen anything of this sort before.