C program to input any alphabet and check whether it is vowel or consonant – In this article, we will demonstrate the way to check whether any inputted alphabet is a vowel or consonant in C programming.
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.
In this piece, the method used is as follows:
- Using Standard Method
As given in the image uploaded above, you need to enter a character.
We all know, there are 5 vowels in the 26 alphabets of the English language.
Those are A, E, I, O and U
In this case, it is seen that ‘a’ is the character that has been entered.
So, it is clear that ‘a’ is a vowel. The same thing will be printed on the screen.
Thus, the means to do so in C programming are as follows:
Using Standard Method
- Read the entered character and save in the variable “ch” using scanf() function.
2) Compare “ch” with all vowels(A,a,E,e,I,i,O,o,U,u) using “if” condition.
3) If “ch” matches with any one of the vowels then print ch is a vowel, otherwise print ch is consonant.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include<stdio.h> #include<conio.h> int main() { char ch; printf("Enter a character\n"); scanf("%c",&ch); if (ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U') printf("%c is a vowel\n",ch); else printf("%c is a consonant\n",ch); } |
1 2 3 |
Enter a character a a is a vowel |