C program to check vowel or consonant using switch | Easy Explanation in 6 cases
C program to check vowel or consonant using switch.
Question: Implement a C program to check vowel or consonant using switch.
vowel and consonant program in c
For Beginners step by step procedure to solve this check vowel or consonant using switch:
- Understand the question
- Try to think of other test cases than present in the question.
- Try to write a pseudo code for it.
vowel and consonant program in c
Question:
Implement a C
program to check vowel or consonant using switch case.
Input:
An charcter ch
where ch is between a
and z
or A
and Z
.
Output:
Print it’s a vowel
if it is vowel, otherwise it’s a consonant
.
Solution:
vowel and consonant program in c
Hint 1: Which alphabets are vowel, there are 5 vowels only.
Hint 2: You need to create 6 case, 5 for vowels, and 1 for the rest 21 consonants.
Intuition for C program to check vowel or consonant using switch. : So, We have to check vowel or consonant using Switch, we will create 6 cases and if it get matched accordingly we will print.
Read about Switch in C.
vowel and consonant program in c
Important: If break is not given it will keep on executing the below cases. |
Steps to C program to check vowel or consonant using switch :
- Take input using
scanf
in a charch
. - Create 6 cases accordingly.
- Print the required statement.
C program to check vowel or consonant using switch :
vowel and consonant program in c
#include<stdio.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
ch = tolower(ch);
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("%c is a vowel.\n", ch);
break;
default:
printf("%c is a consonant.\n", ch);
}
return 0;
}
vowel and consonant program in c
Thank You!
Visit to See More Coding Solutions.