C Program to Check Vowel or Consonant

Below is the C program to find if a character is a vowel or consonant using an if-else statement.

C




// C program to check if a character
// is a vowel or consonant
#include <stdio.h>
 
// Driver code
int main()
{
    char ch = 'A';
 
    // Checking if the character ch
    // is a vowel or not.
    if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E'
        || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O'
        || ch == 'u' || ch == 'U') {
 
        printf("The character %c is a vowel.\n", ch);
    }
    else {
        printf("The character %c is a consonant.\n", ch);
    }
 
    return 0;
}


Output

The character A is a vowel.

Complexity Analysis

  • Time Complexity: O(1)
  • Auxiliary Space: O(1)

C Program to Check Vowel or Consonant

In English, there are 5 vowel letters and 21 consonant letters. In lowercase alphabets, ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ are vowels and all other characters (‘b’, ‘c’, ‘d, ‘f’….) are consonants. Similarly in uppercase alphabets, ‘A’, ‘E’, ‘I’, ‘O’, and ‘U’ are vowels, and the rest of the characters are consonants.

In this article, we will learn how to write a C program to check if a character is a vowel or consonant.

Similar Reads

Algorithm

The algorithm to check vowels and consonants is simple to understand and implement. Here,...

C Program to Check Vowel or Consonant

Below is the C program to find if a character is a vowel or consonant using an if-else statement....

Check Vowel or Consonant using strchr() Function

...