C Program to Check Vowel or Consonant

The characters A, E, I, O, U are known as vowels. The remaining 21 characters of English alphabets are known as consonants.

Example 1: Program to Check Vowel or Consonant using if…else Statement

#include<stdio.h>
int main()
{
    char c, x;
    printf (“Enter a character n”);
    scanf(“%c”, &c);

    if (c==’A’ || c==’a’ || c==’E’ || c==’e’ || c==’I’ || c==’i’ || c==’O’ || c==’o’ || c==’U’ || c==’u’)
          printf (“n The entered character is VOWEL.”);
    else
          printf (“n The entered character is CONSONANT.”);

    return 0;
}

Here, the program asks user for an input and the character entered by user is stored in variable c. Now the variable c is compared with the vowels a, e, i, o and u in both uppercase and in lowercase. If the condition is true then, “The entered character is VOWEL.” appears on the screen. Otherwise, “The entered character is CONSONANT.” is displayed on the screen.

Another method of checking whether the entered character is vowel or consonant in C programming is by converting the entered character to either uppercase or lowercase by using function toupper() and tolower() respectively and then checking if the character c is in uppercase or lowercase respectively.

Example 2: Program to Check Vowel or Consonant using if…else Statement and toupper() Function

The source code for converting the character into uppercase and then using the uppercase character for checking whether the entered character is vowel or consonant is as follows:

#include<stdio.h>
#include<ctype.h>

int main()
{
     char b, c, x;
     printf ("Enter a character n");
     scanf("%c", &b);

     c = toupper(b);

     if (c=='A' || c=='E' || c=='I' || c=='O' || c=='U')
          printf ("n The entered character is VOWEL.");
     else
          printf ("n The entered character is CONSONANT.");

     return 0;

}

Example 3: Program to Check Vowel or Consonant using if…else Statement and tolower() Function

And, the source code in C programming for converting the character into lowercase and then using the lowercase character to check if the entered character is vowel or not is as follows:

#include<stdio.h>
#include<ctype.h>
int main()
{
     char b, c, x;
     printf ("Enter a character n");
     scanf("%c", &b);

     c = tolower(b);

     if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
           printf ("n The entered character is VOWEL.");
     else
           printf ("n The entered character is CONSONANT.");

     return 0;
}

Output

Enter a character
i
The entered character is VOWEL.
Enter a character
L
The entered character is CONSONANT.