C Program to Check Vowel or Consonant

How to write a C Program to Check Vowel or Consonant with an example?. In English, five alphabets A, E, I, O, and U called Vowels. All the remaining alphabets except these five called consonants.

C Program to Check Vowel or Consonant

This program allows the user to enter any character and check whether the user-specified character is Vowel or Consonant using If Else Statement.

// C Program to Check Vowel or Consonant
#include <stdio.h>

int main()
{
    char ch;

    printf("Please Enter an alphabet: \n");
    scanf(" %c", &ch);
    
    if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
		ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')  {
		printf("\n %c is a VOWEL.", ch);
	}
    else {
    	printf("\n %c is a CONSONANT.", ch);
	}
    return 0;
}
C Program to Check Vowel or Consonant 1

The following C programming statement will ask the user to enter any character, and then we are assigning the character to previously declared variable ch

printf("Please Enter an alphabet: \n");
scanf(" %c", &ch);

Next, we used the If Else Statement to check whether the user entered character is equal to a, e, i, o, u, A, E, I, I, O. And if it is TRUE, it is a Vowel otherwise, it’s a Consonant.

Remember, you can convert all the characters to one case using strlwr or strupr and then check for lowercase or uppercase elements in the If condition

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

C Program to Check whether a Character is Vowel or Consonant – Approach 2

This program to Check Vowel or Consonant is same as an above program, but we arranged the code more readable

// C Program to Check Whether a Character is Vowel or Consonant
#include <stdio.h>

int main()
{
    char ch;
    int lowercase_Vowel, uppercase_Vowel;

    printf("Please Enter an alphabet: \n");
    scanf(" %c", &ch);

    lowercase_Vowel = (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
    uppercase_Vowel = (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U');

    if (lowercase_Vowel || uppercase_Vowel) {
    	printf("\n %c is a VOWEL.", ch);
	}
    else {
    	printf("\n %c is a CONSONANT.", ch);
	}
    return 0;
}
Please Enter an alphabet: 
I

 I is a VOWEL.

OUTPUT 2: Let us enter the Consonant value

Please Enter an alphabet: 
g

 g is a CONSONANT.

C Program to find Vowel or Consonant using Functions

This C program allows the user to enter any character, and find whether the user-specified character is Vowel or Consonant using Functions.

// C Program to Check Whether an Alphabet is Vowel or Consonant
#include <stdio.h>
int check_vowel(char a);
int main()
{
    char ch;
    printf("Please Enter an alphabet: \n");
    scanf(" %c", &ch);
    
    if(check_vowel(ch))  {
		printf("\n %c is a VOWEL.", ch);
	}
    else {
    	printf("\n %c is a CONSONANT.", ch);
	}
    return 0;
}

int check_vowel(char c)
{
    if (c >= 'A' && c <= 'Z')
       c = c + 32; 
 
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
       return 1;
 
    return 0;
}
Please Enter an alphabet: 
e

 e is a VOWEL.

OUTPUT 2: Let us enter the Consonant value

Please Enter an alphabet: 
M

 M is a CONSONANT.

C Program to Check Vowel or Consonant using ASCII Values

This C program allows the user to enter any character. Next, it will check whether the specified character is Vowel or Consonant using ASCII Values.

// C Program to Check Whether it is Vowel or Consonant
#include <stdio.h>
 
int main()
{
    char ch;
 
    printf("Please Enter an alphabet: \n");
    scanf(" %c", &ch);
 
    if(ch == 97 || ch == 101 || ch == 105 || ch == 111 || ch == 117 || 
	ch == 65 || ch == 69 || ch == 73 || ch == 79 || ch == 85)
    {
    	printf("%c is a VOWEL.\n", ch);
    }
    else if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
    {
        printf("%c is a CONSONANT.\n", ch);
    }
 
    return 0;
}
Please Enter an alphabet: 
u
u is a VOWEL.

Let us enter the Consonant value

Please Enter an alphabet: 
K
K is a CONSONANT.