Find an array element such that all elements are divisible by it | C # program to find an array element that divides all numbers in the array using naive approach ; function to find smallest num ; traverse for all elements ; stores the minimum if it divides all ; Driver code
using System ; class GFG { static int findSmallest ( int [ ] a , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < n ; j ++ ) if ( a [ j ] % a [ i ] >= 1 ) break ; if ( j == n ) return a [ i ] ; } return - 1 ; } public static void Main ( ) { int [ ] a = { 25 , 20 , 5 , 10 , 100 } ; int n = a . Length ; Console . WriteLine ( findSmallest ( a , n ) ) ; } }