Program to count vowels in a string ( Iterative and Recursive ) | C ++ program to count vowels in a string ; Function to check the Vowel ; Returns count of vowels in str ; if ( isVowel ( str [ i ] ) ) Check for vowel ; Main Calling Function ; string object ; Total numbers of Vowel
#include <iostream> NEW_LINE using namespace std ; bool isVowel ( char ch ) { ch = toupper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } int countVowels ( string str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) ++ count ; return count ; } int main ( ) { string str = " abc ▁ de " ; cout << countVowels ( str ) << endl ; return 0 ; }