C Program to Check Whether a Character is Vowel or Consonant

A vowel is the alphabets that represents a speech sound created by the relatively free passage of breath through the larynx and oral cavity. Letters that are not vowels are consonants. English has five proper vowel letters (A, E, I, O, U) all alphabets except these characters are consonants.

C Program to check whether an input character is vowel or consonant

In the following program, we take a character as input from user and store in variable c. Then, we check whether it is any one of these ten characters(lower and upper case vowels) a, A, e, E, i, I, o, O, u and U using || operator. If input character is any one of these ten vowel characters, then it is a vowel otherwise a consonant.
#include <stdio.h>

int main(){
    char c;
    printf("Enter a Character: ");
    scanf("%c", &c);
    if(c == 'a'||c == 'e'||c =='i'||c=='o'||c=='u'||c=='A'
          ||c=='E'||c=='I'||c=='O'||c=='U'){
        printf("%c is a Vowel\n", c);
    } else {
        printf("%c is a Consonant\n", c);
    }
    return 0;
}
Output
Enter a Character: A
A is a Vowel
Enter a Character: D
D is a Consonant

C program to check whether a character is vowel or consonant using function

In this program, we first check whether input alphabet is lower case or not using "isLowerCase" function which returns 1 if passed character is lower case character. Then we convert lower case characters to their corresponding upper case character by subtracting 32.

Difference between the ASCII value of any lower case character and it's corresponding upper case character is 32 ('A' + 32 = 'a'). After conversion of lower to upper case char, it checks whether it is vowel or consonant using isVowel function.

#include <stdio.h>

#define LOWERCASE_TO_UPPERCASE_DIFFERENCE  32

int isVowel(char c);
int isLowerCase(char c);

int main(){
    char c;
    printf("Enter a Character: ");
    scanf("%c", &c);

    if(isVowel(c)){
        printf("%c is a Vowel\n", c);
    } else {
        printf("%c is a Consonant\n", c);
    }
  
    return 0;
}

int isVowel(char c){
    if(isLowerCase(c))
    c = c - LOWERCASE_TO_UPPERCASE_DIFFERENCE; 
 
    if (c == 'A'||c == 'E'||c == 'I'||c == 'O'||c == 'U')
       return 1;
    else 
       return 0;
}

int isLowerCase(char c){
    if(c >= 'a' && c<= 'z')
        return 1;
    else 
        return 0;    
}
Output
Enter a Character: e
e is a Vowel
Enter a Character: f
f is a Consonant

C Program to check whether an alphabet is vowel or consonant using switch statement

To understand this program, you should have knowledge of Switch Statements

#include <stdio.h>
 
int main(){
    char c;
    printf("Enter a Character: ");
    scanf("%c", &c);
    switch(c)
    {
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            printf("%c is a Vowel\n", c);
            break;
        default:
            printf("%c is a Consonant\n", c);
    }    
    return 0;
}
Output
Enter a Character: A
A is a Vowel

Related Topics
C program to check year is leap year or not
C program to check odd or even numbers
C program to check a number is palindrome or not
C program to check armstrong number
C Program to find frequency of characters in a string
C program to add two complex numbers
C Program to calculate factorial of a number
List of all C programs