Minimum and Maximum element of an array which is divisible by a given number k | C # implementation of the above approach ; Function to find the minimum element ; Function to find the maximum element ; Driver code
using System ; class GFG { static int getMin ( int [ ] arr , int n , int k ) { int res = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { res = Math . Min ( res , arr [ i ] ) ; } } return res ; } static int getMax ( int [ ] arr , int n , int k ) { int res = int . MinValue ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) { res = Math . Max ( res , arr [ i ] ) ; } } return res ; } static public void Main ( ) { int [ ] arr = { 10 , 1230 , 45 , 67 , 1 } ; int k = 10 ; int n = arr . Length ; Console . WriteLine ( " Minimum ▁ element ▁ of ▁ array ▁ " + " which ▁ is ▁ divisible ▁ by ▁ k : ▁ " + getMin ( arr , n , k ) ) ; Console . WriteLine ( " Maximum ▁ element ▁ of ▁ array ▁ " + " which ▁ is ▁ divisible ▁ by ▁ k : ▁ " + getMax ( arr , n , k ) ) ; } }