Q. C++ program to check whether a character is vowel or consonant.
Here you will find an algorithm and program in C++ programming language to check whether the given character is vowel or consonant.
Explanation : In English, five alphabets A, E, I, O, and U are called as Vowels. In English, all alphabets other than vowels are Consonant.
Algorithm to check whether a character is vowel or consonant
START Step 1 - Input the alphabets. Step 2 - Check if the alphabets is (a, e, i, o, u) if alphabet is among these then it is vowel. Step 3 - If the alphabets is vowel than print Vowel otherwise print Consonant. STOP
C++ Program to Check Vowel or Consonant
#include <iostream> using namespace std; int main() { char c='P'; int lc, uc; // evaluates to 1 (true) if c is a lowercase vowel lc = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); // evaluates to 1 (true) if c is an uppercase vowel uc = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); // evaluates to 1 (true) if either lc or uc is true if (lc || uc) cout << c << " is a vowel."; else cout << c << " is a consonant."; return 0; }
Output
P is a consonant.