C Program to Check Whether a Character is Vowel or Consonant - IProgramX

Q. Accept a character from the user and check whether the character is a an vowel or consonant. (Hint: a,e,i,o,u are vowels)


Program

#include <stdio.h>
int main()
{
    char c;
    int isLowercaseVowel, isUppercaseVowel;
    printf("Enter a alphabet: ");
    scanf("%c",&c);
    isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    if (isLowercaseVowel || isUppercaseVowel)
        printf("%c is a vowel.", c);
    else
        printf("%c is a consonant.", c);
}

Output:

Enter a alphabet: t
t is a consonant.

Post a Comment

0 Comments