Write a C program to Check vowel or consonant

Topics

  1. We first declare a character variable c to store the user input.
  2. We prompt the user to enter a character using printf and accept the input using scanf.
  3. We check if the entered character is a vowel or a consonant using the if condition. If the character matches any of the vowel characters (lowercase or uppercase), we print a message saying that the character is a vowel. Otherwise, we print a message saying that it is a consonant.
  4. Finally, we return 0 to indicate successful execution of the program.
  5. this program assumes that the user enters a single character only. If you need to accept a string as input and check each character individually, you will need to modify the program accordingly.
#include <stdio.h>

int main() {
    char c;

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

    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
        printf("%c is a vowel.\n", c);
    } else {
        printf("%c is a consonant.\n", c);
    }

    return 0;
}

OUTPUT

Enter a character: t
t is a consonant.

Related Posts

Leave a Reply

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