C Program to input an alphabet and check for a vowel or consonant – In this particular article, we will brief in on how to input an alphabet and check for a vowel or a consonant.
Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.
There has been only one method mentioned in this specific piece to check for a vowel or a consonant.
As given in the photo above, the vowels in the English language are:
The other 21 alphabets are considered as Consonants. Thus, the way to check for a vowel or a consonant in C programming is as follows:
C program to input any alphabet and check whether it is vowel or consonant
1)Read the entered character and check is it a character or not using if condition. If ASCII value is between 65 to 90 or 97 to 122 so entered character is an alphabet.
2)Compare the alphabet with each vowel a, e, i, o, u using if condition, if it matches with any one of the vowels then it prints “character is vowel”, otherwise it prints “character is consonant”.
3)If the entered character ASCII value is not in the range between 65 to 90 or 97 to 122 then it prints “character is not an alphabet”.
printf("enter character :");
if(ch>=65 && ch<=90 || ch>=97 && ch<=122)
if(ch=='a' ||ch=='e' ||ch=='i' ||ch=='o' ||ch=='u' ||ch=='A' ||ch=='E' ||ch=='I' ||ch=='O' ||ch=='U')
printf("character is vowel");
printf("character is consonant");
printf("character is not aphabet");
enter character :p
character is consonant