Thursday, 21 August 2014

Filled Under: ,

C Program to Check Whether Alphabet is Vowel or Consonant

Share

Here is a simple C Program to Check  Whether Alphabet is Vowel or Consonant is given below.Which takes an alphabet as input and identify that input alphabet is vowel or consonant.Alphabets a, e, i, o and u are known as vowels and all alphabets except these characters are known as consonants.This program asks user to enter a character and checks whether that input alphabet  is  vowel or not. This task can be performed in C programming using if…else statement.

C Program to Check  Whether Alphabet is Vowel or Consonant

#include <stdio.h>
int main(){
  char c;
  printf("Enter an alphabet: ");
  scanf("%c",&c);
  if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U')
       printf("%c is a vowel.",c);
  else
       printf("%c is a consonant.",c);
  return 0;
}
Output 1:
Enter an alphabet: i
i is a vowel.
Output 2:
Enter an alphabet: G
G is a consonant.


Explanation

In this program, user is asked to enter a character which is stored in variable c. Then, this character is checked, whether it is any one of these ten characters a, A, e, E, i, I, o, O, u and U using logical OR operator ||. If that character is any one of these ten characters, that alphabet is a vowel if not that alphabet is a consonant.