Count consonants in a string ( Iterative and recursive methods ) | Recursive C # 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
using System ; class GFG { static Boolean isConsonant ( char ch ) { ch = char . ToUpper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) == false && ch >= 65 && ch <= 90 ; } static int totalConsonants ( String str , int n ) { if ( n == 1 ) { if ( isConsonant ( str [ 0 ] ) ) return 1 ; else return 0 ; } if ( isConsonant ( str [ n - 1 ] ) ) return totalConsonants ( str , n - 1 ) + 1 ; else return totalConsonants ( str , n - 1 ) ; } public static void Main ( String [ ] args ) { String str = " abc ▁ de " ; Console . WriteLine ( totalConsonants ( str , str . Length ) ) ; } }