Count of elements not divisible by any other elements of Array | C # program for the above approach ; Function to count the number of elements of array which are not divisible by any other element in the array [ ] arr ; Iterate over the array ; Check if the element is itself or not ; Check for divisibility ; Return the readonly result ; Driver Code ; Given array ; Function call
using System ; class GFG { static int count ( int [ ] a , int n ) { int countElements = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bool flag = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) continue ; if ( a [ i ] % a [ j ] == 0 ) { flag = false ; break ; } } if ( flag == true ) ++ countElements ; } return countElements ; } public static void Main ( String [ ] args ) { int [ ] arr = { 86 , 45 , 18 , 4 , 8 , 28 , 19 , 33 , 2 } ; int n = arr . Length ; Console . Write ( count ( arr , n ) ) ; } }