Skip to main content

C Program to check character is vowel or consonant

This C Language code will check whether entered character is vowel or consonant.

“A”, “E”,”I”,”O”,”U” either in upper or lower case character are vowels. Other than “A”, “E”,”I”,”O”,”U” all characters between A to Z are consonant.


//Program Name: Accept a lower or Upper case character from the user 
//and check whether the character is a vowel or consonant.

#include<stdio.h>
#include<conio.h>
 void main()
 {
   char ch;
   printf("\nEnter character to check for Vowel or Consonant: ");
   ch=getchar();

   if((ch >= 'a' && ch <= 'z') || (ch >= 'A' &&ch <= 'Z'))
   {
       if(ch=='a'||ch=='i'||ch=='o'||ch=='u'||ch=='e' ||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
	       printf("\n\n %c is Vowel ",ch);
	    else
	       printf("\n\n %c is Consonant ",ch);
   }
   else
      printf("\n\n %c is not character",ch);
    
   getch();
 }

Output

Enter character to check for Vowel or Consonant: p

p is Consonant

Enter character to check for Vowel or Consonant: e

e is Vowel

Enter character to check for Vowel or Consonant: 3

3 is not character

Program is accepting input as single character and storing it in variable “ch”. In If condition it is validating whether entered character is in between lower/upper case A to Z. After successful validation it is comparing characters with vowels if not matched then it shows output as consonant.

Any character which does not belong to A to Z, Program is treating it as “invalid input”.