Check Vowel or Consonant using find() Function
In the below C++ program, the find() function is used to search for the character in the string containing vowel letters. If the character is found, the isVowel function return 1, else it returns 0.
C++
// C++ program to check vowel or consonant using find() // function #include <iostream> #include <string> using namespace std; int isVowel( char ch) { // Make the list of vowels string str = "aeiouAEIOU" ; return (str.find(ch) != string::npos); } // Driver code int main() { if (isVowel( 'a' )) cout << "a is vowel" << endl; else cout << "a is consonant" << endl; return 0; } |
Output
a is vowel
Complexity Analysis
- Time Complexity: O(1)
- Auxiliary Space: O(1)
Refer to the complete article Program to find if a character is vowel or Consonant for more methods to check if a character is a vowel or consonant.
C++ Program To Find If A Character Is Vowel Or Consonant
In English Alphabet, vowels are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’. The rest of the remaining characters (like ‘b’, ‘c’, ‘d’, ‘f’ ….) are consonants. In this article, we will learn to write a C++ program to check whether a character is Vowel or Consonant.
Contact Us