In this tutorial you will learn about the C Program to check vowel or consonant and its application with practical example.
In this tutorial, we will learn to create a C program that will check whether the entered alphabet by the user is a vowel or a consonant using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- C Operators
- Condition statement.
- logical operator.
What Is Vowel and consonant?
Vowel :=> Sound that allowing breath to flow out of mouth, without closing any part of the mouth.
Consonant:=> Sound made by blocking air from flowing out of the mouth with the teeth or throat.
Example
As we know A E I O U are called vowels. And renaming alphabets except these 5 vowels are called consonants.
Program to Check the given value is Vowel or consonant.
So here we creating a program in which we will find the given character is vowel or consonant.
As we know a,e,i,o,u are only vowel and rest are consonant.So simply we will check these and if given character belongs to them then it is a vowel simple let’s have a look at program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<stdio.h> int main() { char ch; printf("enter any characetr\n:"); scanf("%c",&ch); //taking value from user. // checking condition for upper and lower case both..... if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' &&ch <= 'Z')) { 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); } else // checking if value given is not character... { printf("%c is neither a vowel nor a consonant.\n",ch); } return 0; } |
Output
Note: Here we assumes that the user will enter an alphabet. If not so then non-alphabetic character, it displays the character is neither a vowel nor a consonant.
In the above program, we have first declared a variables required in the program.
- ch= hold given character.
First of all user will be prompted to enter any character.Then with the help of program we will check whether inputted character is a vowel or consonant,using following logic
As user inputs any character we check whether it’s a vowel both lower-case and upper-case are checked
If a character belong to this condition then it is vowel,and if doesn’t meet it’s a consonant,and here we also check if it is not vowel and consonant it might be a digit or a special symbol.
So in this tutorial we have learn to find given character is vowel or consonant.