CPP program to check character is vowel or consonant
In this program, you will learn how to check the character is a vowel or not in the cpp programming language.
There are five alphabets a,I,o,u, and e are vowels other are consonant.
For understanding, you should have knowledge about the following topics.
Following is the code.
code:
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "Enter an alphabet: ";
cin >> ch;
if(ch == 'a' || ch == 'e' || ch== 'i' || ch == 'o' || ch == 'u')
{
cout << ch << " is a vowel.";
}
else if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
cout << ch << " is a vowel.";
}
else
cout << ch << " is a consonant.";
return 0;
}
Output:
Enter an alphabet: A
A is a vowel.
Here, in the above program if-else is used to decide the alphabet is vowel or not . In the first if-check check the vowels in the lower case and in the second if-check check the vowels in the upper case . Else alphabet is consonant.
Comments
Post a Comment