
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Whether a Character is Vowel or Consonant in C++
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;
Advertisements