Program to count vowels in a string ( Iterative and Recursive ) | Recursive C ++ program to count the total number of vowels using recursion ; Function to check the Vowel ; to count total number of vowel from 0 to n ; 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 countVovels ( string str , int n ) { if ( n == 1 ) return isVowel ( str [ n - 1 ] ) ; return countVovels ( str , n - 1 ) + isVowel ( str [ n - 1 ] ) ; } int main ( ) { string str = " abc ▁ de " ; cout << countVovels ( str , str . length ( ) ) << endl ; return 0 ; }