In this example, we take one character input from user and check inputted character is vowel or consonant.
Given a character, check if it is vowel or consonant. Vowels are ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’. All other characters are consonants.
Example :
#include <stdio.h>
int main()
{
char ch;
// Input character from user
printf("Enter any character: ");
scanf("%c", &ch);
//Condition for vowel
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||
ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
printf("'%c' is Vowel.", ch);
}
else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
//Condition for consonant
printf("'%c' is Consonant.", ch);
}
else
{
//If it is neither vowel nor consonant then it is not an alphabet.
printf("'%c' is not an alphabet.", ch);
}
return 0;
}
Output :
//Output :- 1
Enter any character: a
'a' is Vowel.
//Output :- 2
Enter any character: !
'!' is not an alphabet.
//Output :- 3
Enter any character: x
'x' is Consonant.
Ask anything about this examples