Question

Write a C program to check if the entered character is a vowel or consonant using a switch statement.

Updated on May 31, 2025 | By Learnzy Admin | 👁️ Views: 361 students

Solution
✔ Verified

In C programming, we can use a switch statement to check whether a given character is a vowel or consonant. The switch statement provides a clean and efficient way to evaluate multiple conditions. In this case, the program first asks the user to input a character. It then compares the character against the vowels ('a', 'e', 'i', 'o', 'u') in both uppercase and lowercase using a switch statement.

If the character matches any of these vowels, the program prints a message indicating that the character is a vowel. If there is no match, the default case of the switch is executed, and the program prints that the character is a consonant. 

#include <stdio.h>

int main() {
    char ch;
    printf("Enter a letter: ");
    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 a letter: d
d is a consonant

 

Was this solution helpful? 47
Click here to download practice questions on Switch statement in C

More Questions on Switch statement in C

Question 1

Write a C program to find the day of the week based on an input number using a switch statement


View solution
Question 2

Write a program in C to create a simple calculator using the switch statement.


View solution