C code to check a character is a vowel or consonant

Character is a vowel or consonant in C

Here, in this section we will discuss the program to check whether the character is a vowel or consonant in C. In this program we take a character from the user then check that entered character. A character is said to be a vowel if it is one of the five following alphabet – a, e, i, o, u. All the remaining alphabets are called consonants i.e. b, c, d, f, g, h, i, j, k, l, m, n etc are the consonants.

Now in here we will see how we can identify whether a character is a vowel or consonant using the C programming language.

Example :    Input => i

                      Output => i is a vowel

                      Input => T

                     Output => T is a consonant

Character is a vowel or consonant

Working:-

We check whether given character matches any of the 5 vowels. If yes, we print “Vowel”, else we print “Consonant”.

  • This C program allows the user to enter any character and check whether the user specified character is Vowel or Consonant using If Else Statement.
  • This program takes the character value(entered by user) as input.
  • And checks whether that character is a vowel or consonant using if-else statement.
  • Since a user is allowed to enter an alphabet in lowercase and uppercase, the program checks for both uppercase and lowercase vowels and consonants.
  • And now we have to follow step’s of  C programming
Characters is a vowel or consonant in C
Competitive Coding Techniques

C program to check whether a character is a vowel or consonant:-

#include <stdio.h>
int main()
{
char c;
int isLowerVowel, isUpperVowel;
printf("Enter an alphabet: ");
scanf("%c",&c);

//To find the corrector is lowercase vowel
isLowerVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
//To find the character is Upper case vowel
isUpperVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// compare to charector is Lowercase Vowel or Upper case Vowel

if (isLowerVowel || isUpperVowel)
printf("%c is a vowel", c);

//to check character is alphabet or not
else if(!((c >= 'a' && c <='z') || (c >= 'A' && c <= 'Z')))
printf("%c not a alphabet", c);

else
printf("%c is a consonant", c);

return 0;
}


output: Enter an alphabet: d d i the consonant Enter an alphabet: a a is vowel
 

5 comments on “C code to check a character is a vowel or consonant”


  • sachin

    #include
    int main()
    {
    int lower,upper;
    char ch;
    printf(“ente the character”);
    scanf(“%c”,&ch);
    lower=(ch==’a’|| ch==’e’|| ch==’i’ || ch==’o’ || ch==’u’);
    upper=(ch==’A’|| ch==’E’|| ch==’I’ || ch==’O’ || ch==’U’);
    if(lower || upper)
    {
    printf(“is vowel”);
    }
    else if((ch>=’a’ && ch=’A’ && ch<='Z'))
    {
    printf("is consonant");

    }
    else
    {
    printf("not an alphabet");
    }
    return 0;
    }


  • sachin

    THIS IS BETTER

    #include
    int main()
    {
    int lower,upper;
    char ch;
    printf(“ente the character”);
    scanf(“%c”,&ch);
    lower=(ch==’a’|| ch==’e’|| ch==’i’ || ch==’o’ || ch==’u’);
    upper=(ch==’A’|| ch==’E’|| ch==’I’ || ch==’O’ || ch==’U’);
    if(lower || upper)
    {
    printf(“is vowel”);
    }
    else if((ch>=’a’ && ch=’A’ && ch<='Z'))
    {
    printf("is consonant");

    }
    else
    {
    printf("not an alphabet");
    }
    return 0;
    }