Program to check whether a character is vowel or consonant

In this example, we take one character input from user and check inputted character is vowel or consonant.

C Program to Check Whether a Character is a Vowel or Consonant

Given a character, check if it is vowel or consonant. Vowels are ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’. All other characters are consonants.

Example :

	
#include <stdio.h>
int main()
{
    char ch;

    // Input character from user 
    printf("Enter any character: ");
    scanf("%c", &ch);

    //Condition for vowel
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || 
        ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
    {
        printf("'%c' is Vowel.", ch);
    }
    else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        //Condition for consonant 
        printf("'%c' is Consonant.", ch);
    }
    else 
    {
        //If it is neither vowel nor consonant then it is not an alphabet.
        printf("'%c' is not an alphabet.", ch);
    }
    return 0;
}
	

Output :

	
		//Output :- 1
		Enter any character: a
		'a' is Vowel.
		//Output :- 2
		Enter any character: !
		'!' is not an alphabet.
		//Output :- 3
		Enter any character: x
		'x' is Consonant.
	

Share your thoughts

Ask anything about this examples