🔀Beginner

Check Whether Character is Vowel or Consonant

Character classification

Vowels are the letters A, E, I, O, U (and their lowercase versions). All other alphabets are consonants. This program demonstrates character comparison and logical operators.

C Program to Check Vowel or Consonant

vowel_consonant.c
C
1#include <stdio.h>
2#include <ctype.h> // For tolower()
3
4int main() {
5 char ch;
6
7 printf("Enter a character: ");
8 scanf("%c", &ch);
9
10 // Convert to lowercase for easier comparison
11 ch = tolower(ch);
12
13 // Check if it's an alphabet first
14 if (ch >= 'a' && ch <= 'z') {
15 // Check if vowel
16 if (ch == 'a' || ch == 'e' || ch == 'i' ||
17 ch == 'o' || ch == 'u') {
18 printf("'%c' is a Vowel\n", ch);
19 } else {
20 printf("'%c' is a Consonant\n", ch);
21 }
22 } else {
23 printf("'%c' is not an alphabet\n", ch);
24 }
25
26 return 0;
27}
Output

Enter a character: E

'e' is a Vowel

Code Breakdown

tolower(ch)

Converts uppercase to lowercase. Makes comparison easier - we only check a, e, i, o, u instead of both cases.

ch >= 'a' && ch <= 'z'

Uses logical AND (&&) to check if character is between 'a' and 'z' (an alphabet).

ch == 'a' || ch == 'e' || ...

Uses logical OR (||) to check if character matches ANY vowel.

Logical Operators

OperatorNameDescription
&&ANDTRUE if BOTH conditions are true
||ORTRUE if ANY condition is true
!NOTReverses the condition

Alternative: Using Switch

main.c
C
1switch(tolower(ch)) {
2 case 'a': case 'e': case 'i': case 'o': case 'u':
3 printf("Vowel");
4 break;
5 default:
6 printf("Consonant");
7}

📝 Key Takeaways

tolower() converts to lowercase
&& = AND, || = OR
Vowels: A, E, I, O, U
Always validate input first