C++ program to check whether Character is a vowel or consonant

Check Character is a vowel or consonant

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 => A

                      Output => A is a vowel

                      Input => R

                     Output => R 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
C++ program to check whether Character is a vowel or consonant
Competitive Coding Techniques

C++ Code:-

//C++ Program to check whether alphabet is vowel or consonant
#include <iostream>
using namespace std;
//main function
int main()
{
	char c;
	cout<<"Enter an alphabet: ";
	cin>>c;
        //checking for vowels	
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
	{
		cout<<c<<" is a vowel";     //condition true input is vowel
	}
	else
	{
		cout<<c<<" is a consonant";     //condition false input is consonant
	}
	return 0;
}
Output:
Enter an alphabet:j
j is a constant