Smallest positive integer that does not divide any elements of the given array | C # program for the above approach ; Function to find the smallest number which doesn 't divides any integer in  the given array arr[] ; Traverse the array arr [ ] ; Maximum array element ; Initialize variable ; Traverse from 2 to max ; Stores if any such integer is found or not ; If any array element is divisible by j ; Smallest integer ; Print the answer ; Driver Code ; Function Call
using System ; public class GFG { static void smallestNumber ( int [ ] arr , int len ) { int maxi = 0 ; for ( int i = 0 ; i < len ; i ++ ) { maxi = Math . Max ( maxi , arr [ i ] ) ; } int ans = - 1 ; for ( int i = 2 ; i < maxi + 2 ; i ++ ) { bool flag = true ; for ( int j = 0 ; j < len ; j ++ ) { if ( arr [ j ] % i == 0 ) { flag = false ; break ; } } if ( flag ) { ans = i ; break ; } } Console . WriteLine ( ans ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 3 , 2 , 6 , 9 , 2 } ; int N = arr . Length ; smallestNumber ( arr , N ) ; } }