Knowee
Questions
Features
Study Tools

Write a C program to check whether an alphabet is vowel or consonant using switch case

Question

Write a C program to check whether an alphabet is vowel or consonant using switch case

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C program that checks whether the entered alphabet is a vowel or a consonant using a switch case statement:

#include <stdio.h>

int main() {
    char alphabet;

    // Prompt the user to enter an alphabet
    printf("Enter an alphabet: ");
    scanf("%c", &alphabet);

    // Check if the input is a letter
    if ((alphabet >= 'a' && alphabet <= 'z') || (alphabet >= 'A' && alphabet <= 'Z')) {
        // Convert to lowercase for easier comparison
        switch (alphabet) {
            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", alphabet);
                break;
            default:
                printf("%c is a consonant.\n", alphabet);
                break;
        }
    } else {
        printf("Invalid input. Please enter a valid alphabet.\n");
    }

    return 0;
}

Explanation:

  1. The program prompts the user for an input character.
  2. It checks whether the input character is a letter (either uppercase or lowercase).
  3. It uses a switch statement to determine if the letter is a vowel (a, e, i, o, u) or a consonant.
  4. It prints the result accordingly. If the input is not a valid letter, it notifies the user of the invalid input.

You can compile and run this program in a C programming environment.

This problem has been solved

Similar Questions

Write a C program to read an English Alphabet through keyboard and display whetherthe given alphabet is in upper case or lower case.

Write a program to check whether a given character is Alphabet or not using if else statement Note: Check for both upper and lower case characters

Write a C program to read a sentence and replace lowercase characters with uppercase and vice versa.

Define a class to accept a string and convert it into uppercase. Count and display thenumber of vowels in it.

#Write a Python function count_vowels(text) that takes a string as input and returns the count of vowels (a, e, i, o, u) in the input string, ignoring case.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.