Home >>c programs >c program to check vowel or consonant 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; }
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; }