C

# C Program to check whether an alphabet is vowel or consonant

## Program to check whether an alphabet is a vowel or consonant in C language:

or

### C program to check an alphabet is vowel or consonant

In this article, you’ll learn to check whether an alphabet entered by the user is consonant or vowel in C program with example and explain in detail.

As we know that: A, E, I, O, U or a, e, i, o, u is a vowel except this all are consonant in the alphabet A to Z.

Step by step explanation:

• First, we create three variables, they are lowercase, uppercase, and alpha
• Print “ Enter an alphabet “ on the screen
• User give an input which is alphabet then
• We Store input alphabet which is entered by the user in the alpha variable with the help of predefined function scanf then
• We check input alphabet is vowel or not
• If vowel then print on screen alphabet is a vowel
• Otherwise, print on screen alphabet is consonant

Q: write a program in c language to check whether an alphabet is vowel or consonant input is given by user from the keyboard.

Solution:

 #include #include int main() { int lowerCase, upperCase; char alpha; printf(“Enter an alphabet: “); scanf(“%c”,&alpha); upperCase=(alpha==’A’ || alpha==’E’ || alpha==’I’ || alpha==’O’ || alpha==’U’); lowerCase=(alpha==’a’ || alpha==’e’ || alpha==’i’ || alpha==’o’ || alpha==’u’); if(upperCase || lowerCase) printf(“%c is a vowel”,alpha); else printf(“\n%c is a consonant”,alpha); return 0; }

 The output of this program: Enter an alphabet: E E is a vowel

Note: if the user enters any number except vowel then print on screen “  is a consonant” because this programming only checking alphabet is vowel or consonant.

Q: write a program in c language to check whether an alphabet is a vowel or consonant using do-while, an input is given by user from the keyboard.

Solution:

 #include #include int main() { int lowerCase, upperCase; char alpha; do{ printf(“Enter an alphabet: “); scanf(“%c”,&alpha); } while (!(alpha)); upperCase=(alpha==’A’ || alpha==’E’ || alpha==’I’ || alpha==’O’ || alpha==’U’); lowerCase=(alpha==’a’ || alpha==’e’ || alpha==’i’ || alpha==’o’ || alpha==’u’); if(upperCase || lowerCase) printf(“%c is a vowel”,alpha); else printf(“\n%c is a consonant”,alpha); return 0; }

 The output of this program: Enter an alphabet: A A is a vowel

You may also learn the following programming: