Find minimum GCD of all pairs in an array | C # program to find the minimum GCD of any pair in the array ; Function returns the minimum GCD of any pair ; Finding GCD of all the elements in the array . ; Driver code
using System ; class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; else return __gcd ( b , a % b ) ; } static int MinimumGCD ( int [ ] arr , int n ) { int g = 0 ; for ( int i = 0 ; i < n ; i ++ ) { g = __gcd ( g , arr [ i ] ) ; } return g ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 6 , 8 , 3 } ; int N = arr . Length ; Console . WriteLine ( MinimumGCD ( arr , N ) ) ; } }