In this post, you will be able to learn various methods to check the entered character is vowel or consonant using C Programming language.
C Program to Check Vowel or Consonant using Switch Statement
In the below example program capital and small case letters are checked for vowel or consonant. The user has to enter only characters only.
Program
#include<stdio.h>
int main()
{
char var;
printf("Enter a character\n");
scanf("%c",&var);
switch(var)
{
case 'a||A':
case 'e||E':
case 'i||I':
case 'o||O':
case 'u||U':
printf("Entered character is vowel\n");
break;
default: printf("Entered character is Consonant\n");
}
return 0;
}
Output
Code Explanation
First, declare a variable of type char. Using printf()
function ask the user to enter a character. Using scanf()
function, read an input character.
The switch statement checks the character is vowel or not.
If an entered character is vowel then print the statement “Entered character is a vowel. otherwise, print the statement “Entered character is Consonant” in the default block.
C Program to Check Vowel or Consonant using if-else
Program
#include<stdio.h>
int main()
{
char var;
printf("Enter a character\n");
scanf("%c",&var);
if (var == 'a' || var == 'A' || var == 'e' || var == 'E' || var == 'i' || var == 'I' || var =='o' || var=='O' || var == 'u' || var == 'U')
printf("given character is vowel\n");
else
printf("given character isn't a vowel\n");
return 0;
}
Output
Code Explanation
First, declare a variable of type char. Using printf()
function ask the user to enter a character. Using scanf()
function, read an input character.
The if-else statement checks the character is vowel or not.
If an entered character is vowel then print the statement “given character is a vowel. otherwise, print the statement “given character is Consonant” in the default block.
People also ask
How do you find vowels and consonants?
Vowels are a,e,i,o,u, and all the other characters are consonants.