Count consonants in a string ( Iterative and recursive methods ) | Recursive CPP program to count total number of consonants ; Function to check for consonant ; To handle lower case ; to count total number of consonants from 0 to n - 1 ; Driver code
#include <iostream> NEW_LINE using namespace std ; bool isConsonant ( char ch ) { ch = toupper ( ch ) ; return ! ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) && ch >= 65 && ch <= 90 ; } int totalConsonants ( string str , int n ) { if ( n == 1 ) return isConsonant ( str [ 0 ] ) ; return totalConsonants ( str , n - 1 ) + isConsonant ( str [ n - 1 ] ) ; } int main ( ) { string str = " abc ▁ de " ; cout << totalConsonants ( str , str . length ( ) ) ; return 0 ; }