Check if the string satisfies the given condition | C # implementation of the approach ; Function that returns true if n is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function that returns true if c is a vowel ; Function that returns true if the count of vowels in word is prime ; If count of vowels is prime ; Driver code
using System ; class GFG { static Boolean prime ( int n ) { if ( n <= 1 ) { return false ; } if ( n <= 3 ) { return true ; } if ( n % 2 == 0 n % 3 == 0 ) { return false ; } for ( int i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } static Boolean isVowel ( char c ) { c = char . ToLower ( c ) ; if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) { return true ; } return false ; } static Boolean isValidString ( String word ) { int cnt = 0 ; for ( int i = 0 ; i < word . Length ; i ++ ) { if ( isVowel ( word [ i ] ) ) { cnt ++ ; } } if ( prime ( cnt ) ) { return true ; } else { return false ; } } public static void Main ( String [ ] args ) { String s = " geeksforgeeks " ; if ( isValidString ( s ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }