How to Write a C Program to Check an Alphabet for Vowel or Consonant
Here we are creating a C Program to Check the Alphabet for Vowel or Consonant using C Programming Language.
In English the alphabets A E I O and U are called as vowels and other remaining alphabets are called as consonants.
Here we are asking the user to enter an alphabet. Then we are checking whether it is a vowel or not by using if else conditional statement and OR operator. We are also checking for uppercase and lowercase alphabets.
Program Source Code : consonant_or_vowel.c
1 #include<stdio.h>
2
3 int main(){
4
5 char ch;
6 int uppercase, lowercase;
7
8 printf("Enter an alphabet : ");
9 scanf("%c",&ch);
10
11 uppercase = ( ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' );
12 lowercase = ( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' );
13
14 if( uppercase || lowercase )
15 printf("%c is a vowel",ch);
16 else
17 printf("%c is a consonant",ch);
18
19 return 0;
20 }
Program Output : Run 1
Enter an alphabet : I
I is a vowel
Program Output : Run 2
Enter an alphabet : u
u is a vowel
Program Output : Run 3
Enter an alphabet : T
T is a consonant
Program Output : Run 4
Enter an alphabet : m
m is a consonant