- In this program we will discuss about how to check whether a character is vowel or consonant.
- In English language will be having 5 vowels and 21 consonants.
- To check entered character is vowel or consonant, first Read input character from user using scanf.
- There are only 5 vowels(A,E,I,O,U), so we need to check entered character is there in those 5 characters.
- If it is present then we can say its an vowel, otherwise it is a consonant.
- While checking we need to consider case sensitivity. So we need to check both uppercase vowels and lower case vowels.
- Lets see an example program to check whether entered character is vowel or not.
Write a program to determine whether the input character is a vowel or consonant or not an alphabet
- #include <stdio.h>
- //write a program to determine whether the input character is a vowel or consonant or not an alphabet
- //c program to check whether a character is vowel or consonant
- //www.InstanceofJava.com
- int main() {
- char character;
- int lowercaseVowel, uppercaseVowel;
- printf("Enter a character ");
- scanf("%c", &character);
- // assigns 1
- lowercaseVowel = (character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u');
- // evaluates to 1 if variable c is a uppercase vowel
- uppercaseVowel = (character == 'A' || character == 'E' || character == 'I' || character == 'O' || character == 'U');
- // evaluates to 1 (true) if c is a vowel
- if (lowercaseVowel || uppercaseVowel)
- printf("%c is a vowel.", character);
- else
- printf("%c is a consonant.", character);
- getch();
- }
Output:
- Enter a character
- I
- I is an vowel
No comments