Signup/Sign In

Program to check if input character is a vowel using Switch Case

Below is a program to check vowel using switch case.

#include<stdio.h>

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");

    char ch;
    printf("Input a Character :  ");
    scanf("%c", &ch);

    switch(ch)
    {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
            printf("\n\n%c is a vowel.\n\n", ch);
            break;
        default:
            printf("%c is not a vowel.\n\n", ch);
    }
    printf("\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}

Output:

Check Vowel using Switch Case


Explanation:

  • If break statement is not used for a case then all the cases following the valid case are executed and evaluated. This way you can make your code easier to understand by writing only break statement only once to check multiple conditions in one go.
  • default is executed only if none of the above cases are true. It is similar to the else statement of the if-else code.