C Program to Check Vowel or Consonant using Switch Case Statement

In this article, we will write a C program to check if a character is a vowel or consonant using a switch case statement.

The program takes an alphabet from the user as input, checks if it is a vowel or consonant using a switch case statement, and prints the output on the screen.

Sample Input:

Enter any alphabet: a

Sample Output:

a is a vowel.

In the English language, alphabets ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ both uppercase and lowercase are known as vowels and the remaining 21 alphabets are known as consonants.

So, to check if the alphabet entered by the user is a vowel or consonant, we have to write 10 case statements which check if the alphabet is a vowel, if not, it will be a consonant.

The following C program takes an alphabet from the user as input, checks if it is a vowel or consonant and prints the output:

#include <stdio.h>

int main() {
    char ch;
    
    printf("Enter any alphabet: ");
    scanf("%c", &ch);
    
    switch (ch) {
        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", ch);
            break;
        default:
            printf("%c is a consonant.\n", ch);
    }
    
    return 0;
}

Output:

Enter any alphabet: a
a is a vowel.

Enter any alphabet: M
M is a consonant.

I hope you liked this article.

Thanks for reading!

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts