In this article, we will discuss the concept of the C program to Check Vowel or consonant using switch case statements
In this post, we are going to learn how to check the vowels and consonants using switch statements in C programming language
The program allows to enter an Alphabet and it checks and displays whether the given alphabet is vowel or consonant with the break statements
Program 1
#include <stdio.h> #include <stdlib.h> int main() { char ch; printf("Enter any Alphabet\n"); //input alphabet from user scanf("%c",&ch);//store the Entered Alphabet in ch switch(ch){ //check lower case vowel letters case 'a': printf("%c is a vowel",ch); break; case 'e': printf("%c is a vowel",ch); break; case 'i': printf("%c is a vowel",ch); break; case 'o': printf("%c is a vowel",ch); break; case 'u': printf("%c is a vowel",ch); break; //check upper case vowel letters case 'A': printf("%c is a vowel",ch); break; case 'E': printf("%c is a vowel",ch); break; case 'I': printf("%c is a vowel",ch); break; case 'O': printf("%c is a vowel",ch); break; case 'U': printf("%c is a vowel",ch); break; default: printf("%c is a consonant",ch); break; } getch(); return 0; }
When the above code is executed, it produces the following result
case 1
Enter any Alphabet a a is a vowel
case 2
Enter any Alphabet E E is a vowel
case 3
Enter any Alphabet M M is a consonant
case 4
Enter any Alphabet y y is a consonant
Approach
The program allows to enter an Alphabet and it checks and displays whether the given alphabet vowel or consonant without the break statements
Program 2
#include <stdio.h> #include <stdlib.h> int main() { char ch; printf("Enter any Alpabet\n"); //input alphabet from user scanf("%c",&ch);//store the Entered Alphabet in ch switch(ch){ //check lower case vowel letters case 'a': case 'e': case 'i': case 'o': case 'u': //check upper case vowel letters case 'A': case 'E': case 'I': case 'O': case 'U': printf("%c is a vowel",ch); break; default: printf("%c is a consonant",ch); break; } getch(); return 0; }
When the above code is executed, it produces the following result
case 1
Enter any Alphabet e e is a vowel
case 2
Enter any Alphabet U U is a vowel
case 3
Enter any Alphabet G G is a consonant
case 4
Enter any Alphabet r r is a consonant
Approach
Suggested for you
Switch case statements in C language
Similar post
Java program to check Vowel or consonant using switch case statements
C++ program to Check Vowel or consonant using switch case statements
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…