Queries to find the count of vowels in the substrings of the given string | C # implementation of the approach ; Function that returns true if ch is a vowel ; Function to return the count of vowels in the substring str [ l ... r ] ; To store the count of vowels ; For every character in the index range [ l , r ] ; If the current character is a vowel ; For every query ; Find the count of vowels for the current query ; Driver code
using System ; class GFG { static int N = 2 ; static Boolean isVowel ( char ch ) { return ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) ; } static int countVowels ( String str , int l , int r ) { int cnt = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( isVowel ( str [ i ] ) ) cnt ++ ; } return cnt ; } static void performQueries ( String str , int [ , ] queries , int q ) { for ( int i = 0 ; i < q ; i ++ ) { Console . WriteLine ( countVowels ( str , queries [ i , 0 ] , queries [ i , 1 ] ) ) ; } } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; int [ , ] queries = { { 1 , 3 } , { 2 , 4 } , { 1 , 9 } } ; int q = queries . GetLength ( 0 ) ; performQueries ( str , queries , q ) ; } }