C program to check vowel or consonant

Write a C program to check whether an alphabet is vowel or consonant using if else. How to check vowels and consonants using if else in C programming. Program to input a character from user and check whether it is vowel or consonant in C. Logic to check vowel or consonant in C program.

Example
Input

Input character: a

Output

'a' is vowel

Required knowledge

Basic C programming, If else

Logic to check vowels or consonants

English alphabets 'a', 'e', 'i', 'o', 'u' both lowercase and uppercase are known as vowels. Alphabets other than vowels are known as consonants.

Below is the step by step descriptive logic to check vowels or consonant.

  1. Input a character from user, store it in some variable say ch.
  2. Check conditions for vowel i.e. if ch == 'a', ch == 'e', ch == 'i', ch == 'o', ch == 'u', then it is vowel.
  3. If the given character is not vowel then check conditions for consonant. If character is alphabet and it is not vowel then it is consonant. Means check ch >= 'a' and ch <= 'z' then, it is consonant

Let us implement the logic with both lower and upper case alphabets.

Program to check vowel or consonant

/**
 * C program to check whether a character is vowel or consonant
 */

#include &ltstdio.h>

int main()
{
    char ch;

    /* Input a character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);


    // Condition for vowel
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
    {
        printf("%c is VOWEL.", ch);
    }
    else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        // Condition for consonant
        printf("%c is CONSONANT.", ch);
    }

    return 0;
}

Note: You can also use ASCII character codes for checking vowels or consonants. Below program explains how to use ASCII character codes to check vowel and consonants.

Program to check vowel or consonant using ASCII values

/**
 * C program to check vowel or consonant using ASCII values 
 */

#include <stdio.h>

int main()
{
    char ch;

    /* Reads any character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);


    // Condition for vowel
    if(ch==97 || ch==101 || ch==105 || ch==111 || ch==117 || ch==65 || ch==69 || ch==73 || ch==79 || ch==85)
    {
        printf("%c is VOWEL.", ch);
    }
    else if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
    {
        // Condition for consonant
        printf("%c is CONSONANT.", ch);
    }

    return 0;
}

Enhance your coding skills by learning this program using other approaches.

Read more - Program to check vowel and consonant using switch case

Output

Enter any character: a
a is VOWEL.

Happy coding 😉

Write your doubts or suggestion. I will try my best to help. You must escape source code before commenting. To format your source code paste your source code inside
<pre><code> ----Your Source Code---- </code></pre>