C program to check whether a character is a vowel or consonant (Including alphabets and non-alphabetic characters)


This program will check whether the character entered by the user is a vowel or a consonant same as the previous one. The difference is that in the previous program we were assuming that the user will enter an alphabet only.

But what if the character entered by the user is not an alphabet?

To tackle this problem, we will use a predefined function of the C language i.e., isalpha() function.

To make this function available, we need to include ‘ctype’ library in our code.

To understand this example, you should know about

1. C programming operators

2. if…else statement

3. Predefined functions(such as isalpha() function)

Vowels are a, e, i, o, u, A, E, I, O, and U.

All other alphabets, including lower case and upper case, except vowels are consonants.



#include<ctype.h> // This library will make isalpha function available

int main()


char schar;

printf("Enter a character:");


if(!isalpha(schar)) //schar is passed in the function to check its behavior


printf("Entered character is not a alphabet");


else if ( (schar=='a' || schar=='e'|| schar=='i'|| schar=='o'|| schar=='u') ||

(schar=='A' || schar=='E'|| schar=='I'|| schar=='O'|| schar=='U') ) // '||'(or) operator is used


printf("Character %c is a vowel",schar);




printf("Character %c is a consonent",schar);


return 0;





The character value entered by the user is ‘’.


When ‘ch’ is passed in the above function it will give true as a result because ‘’ is not an alphabet; thus the block of ‘if’ statement gets executed.



  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.