
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to Check Whether a character is Vowel or Consonant
Vowels are the alphabets a, e, i, o, u. All the rest of the alphabets are known as consonants.
The program to check if a character is a vowel or consonant is as follows −
Example
#include <iostream> using namespace std; int main() { char c = 'a'; if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) cout <<c<< " is a Vowel" << endl; else cout <<c<< " is a Consonant" << endl; return 0; }
Output
a is a Vowel
In the above program, an if statement is used to find if the character is a, e, i, o or u. If it is any of these, it is a vowel. Otherwise, it is a consonant.
This is shown in the below code snippet.
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ) cout <<c<< " is a Vowel" << endl; else cout <<c<< " is a Consonant" << endl;
The above program checks only for lower case characters. So, a program that checks for upper case as well as lower case characters is as follows −
Example
#include <iostream> using namespace std; int main() { char c = 'B'; 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" << endl; else cout <<c<< " is a Consonant" << endl; return 0; }
B is a Consonant
In the above program, an if statement is used to find if the character is a, e, i, o or u (both in upper case as well as lower case).. If it is any of these, it is a vowel. Otherwise, it is a consonant.
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" << endl; else cout <<c<< " is a Consonant" << endl;
- Related Articles
- Java program to find whether given character is vowel or consonant
- Java Program to Check Whether an Alphabet is Vowel or Consonant
- Java program to find whether given character is vowel or consonant using switch case
- Program to find if a character is vowel or Consonant in C++
- Java Program to Check Whether a Character is Alphabet or Not
- C++ Program to Check Whether a Character is Alphabet or Not
- Check whether a character is Lowercase or not in Java
- Check whether a character is Uppercase or not in Java
- Alternate vowel and consonant string in C++
- Java Program to check whether the entered character a digit, white space, lower case or upper case character
- Java Program to check whether the character is ASCII 7 bit
- How to check whether a character is in the Alphabet or not in Golang?
- Alternate vowel and consonant string in C/C++?
- Vowel, other characters and consonant difference in a string JavaScript
- Java Program to check whether the entered character is ASCII 7 bit numeric and character

Advertisements