Write a C program to find whether a given character is a vowel or consonant. A character is taken as input. The character may be in Upper Case or in Lower Case.
In this posts we will be discuss about how to write a program to find whether a given character is a vowel or not, using switch case statement, use of switch case in c, switch case statement,
To perform this task we have to write the c program in the following manner. First, declare a character type variable name
' ch ' then store the input character in by using scanf() function.
After taking the input we have used switch case.
If you want to know basics about C language then checkout this post.
Switch Case :
Just like if-else statement Switch Case statements in C is also used to control the program flow based on some condition, only the difference is: it's used to execute some statement code block if the value of the expression inside the case statement is equal to any of the cases then it will execute the body of that particular statement and if it can't find any matching value then every switch case statement must have some default case value then the default cases body statements will be executed.
Here is the code for Write a C program to find whether a given character is a vowel or consonant.
#include <stdio.h>
int main()
{
char ch;
scanf("%c",&ch); /* It reads a character from the input and store it in ch */
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'o':
case 'O':
case 'I':
case 'i':
case 'U':
case 'u':
{ printf("%c is a vowel.", ch);
break;
}
default:
printf("%c is a consonant.", ch);
}
}
0 Comments