text: Print characters having prime frequencies in order of occurrence | C # code for the above approach ; Function to check primes ; Counting the frequency of all character using Counter function ; Traversing string ; Driver code ; Passing string to checkString function
code: using System ; using System . Collections . Generic ; class GFG { static bool prime ( int n ) { if ( n <= 1 ) return false ; int max_div = ( int ) Math . Floor ( Math . Sqrt ( n ) ) ; for ( int i = 2 ; i < 1 + max_div ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void checkString ( string s ) { Dictionary < char , int > freq = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( ! freq . ContainsKey ( s [ i ] ) ) freq [ s [ i ] ] = 0 ; freq [ s [ i ] ] += 1 ; } for ( int i = 0 ; i < s . Length ; i ++ ) { if ( prime ( freq [ s [ i ] ] ) ) Console . Write ( s [ i ] ) ; } } public static void Main ( ) { string s = " geeksforgeeks " ; checkString ( s ) ; } }