Check for Vowels Using Switch Statement in C

Definition:

A vowel is one of the five English letters: A, E, I, O, U (or a, e, i, o, u). If the entered character matches any vowel, the program displays "It's a vowel". Otherwise, it displays "It's not a vowel".

Explanation:

  • The program accepts a single character from the user.
  • The switch statement compares the entered character with each vowel (a, e, i, o, u).
  • If the character matches any vowel, the program displays "It's a vowel".
  • If no case matches, the default statement executes and displays "It's not a vowel".
  • The break statement stops the execution after a matching case is found.

Program: Check for Vowels Using Switch Statement

Explanation: This program accepts a character from the user and checks whether it is a vowel or not using the switch statement.


#include <stdio.h>
#include <conio.h>

main()
{
    char k;

    clrscr();

    printf("Enter a Character : ");
    scanf(" %c",&k);

    switch(k)
    {
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':

            printf("\nIt's a vowel");
            break;

        default:

            printf("\nIt's not a vowel");
    }

    getch();
}

Output:

Enter a Character : A

It's a vowel


Enter a Character : Z

It's not a vowel

Practice Exercises

Task 1: Write a C program using the switch statement to check whether the entered character is a lowercase vowel or not.

Goal: Learn how to compare character values using the switch statement.
💡 Hint: Check for 'a', 'e', 'i', 'o', and 'u'. If none of these cases match, display "Not a Lowercase Vowel".
💡 Show Solution

#include <stdio.h>
#include <conio.h>

main()
{
    char ch;

    clrscr();

    printf("Enter a Lowercase Character : ");
    scanf(" %c",&ch);

    switch(ch)
    {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':

            printf("\nLowercase Vowel");
            break;

        default:

            printf("\nNot a Lowercase Vowel");
    }

    getch();
}

Output
Enter a Lowercase Character : a

Lowercase Vowel

Enter a Lowercase Character : A

Not a Lowercase Vowel
Explanation: The program accepts a lowercase character and uses the switch statement to check whether it is one of the five lowercase vowels. If the entered character is not a lowercase vowel, the default case displays "Not a Lowercase Vowel".