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