#include <stdio.h>

int main() {
    char character;

    // Input a character from the user
    printf("Enter a character: ");
    scanf(" %c", &character);

    // Check if the input is a letter
    if ((character >= 'A' && character <= 'Z') || (character >= 'a' && character <= 'z')) {
        // Check if the character is a vowel
        if (character == 'A' || character == 'E' || character == 'I' || character == 'O' || character == 'U' ||
            character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u') {
            printf("%c is a vowel.\n", character);
        } else {
            printf("%c is a consonant.\n", character);
        }
    } else {
        printf("Invalid input. Please enter an alphabetic character.\n");
    }

    return 0;
}

Explanation:

Purpose: The program checks if a given character is a vowel or a consonant.

Steps:

  1. Input: It prompts the user to enter a character.
  2. Check Validity: It verifies if the character is a letter (A-Z or a-z).
  3. Determine Type:
    • If it’s a vowel (A, E, I, O, U), it prints that it’s a vowel.
    • If it’s a letter but not a vowel, it prints that it’s a consonant.
  4. Invalid Input: If the input isn’t a letter, it displays an error message.

Output:

1.Enter a character: z
z is a consonant.

2.Enter a character: e
e is a vowel.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights