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:
- A
- E
- I
- O
- U
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”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
include<stdio.h> int main() { char ch; printf("enter character :"); scanf("%c",&ch); 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"); } else printf("character is consonant"); } else printf("character is not aphabet"); } |
1 2 |
enter character :p character is consonant |