Check character is vowel or not is the simple and easy program in c programming.
In this tutorial, we see one simple program which is to Check character is vowel or not. For this, we only require to know what is the vowel.
As we know in alphabet their are 5 vowels and remaining are the consonants. vowels are A, E, I, O, U.
The logic for checking vowels:
- As we know what’s are the vowel on the alphabet. So based on that we write a condition.
- We read character and in if condition we check character with a vowel.
- if the character matches we print it is vowel else its consonant.
Algorithm to check vowel
- Declare character variable to tale input character.
- Take input character from the user.
- Write a condition to check input character equals to a vowel. ( we need to check for both upper and lower case alphabet )
- If true, the print character is a vowel.
- Else, a print character is consonant.
C program to check vowel or consonant using if else
char c ; //declare variable
printf ("Enter character :");
scanf ("%c",&c); //take input character
//write condition to check vowel
printf ("\n Character is vowel ");
printf ("\n Character is consonant ");
1. First we declare the character variable. char c ;
2. Take a input character from user and store character in c variable. Suppose input character is A. c= A.
3. Now the actual logic starts . Check the input character is vowel. Using if we check for vowel.
if (c == ‘A’ || c == ‘a’ || c==’e’ || c==’E’ || c==’i’ || c==’I’ || c==’o’ || c ==’O’ || c==’u’ || c==’U’)
In this statement, c==’A’ checked and condition become true.
4. Condition is true , statement in if block executed.
The character is a vowel.
5. And else block get skipped.
6. And in case of a consonant as another input .the if the condition becomes false and statement in if block gets skipped and else block get executed.
The character is consonant.