GCD of more than two ( or array ) numbers |  ; Recursive function to return gcd of a and b ; recursive implementation ; Driver code
import java . util . * ; class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static int GcdOfArray ( int [ ] arr , int idx ) { if ( idx == arr . length - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = GcdOfArray ( arr , idx + 1 ) ; return __gcd ( a , b ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; System . out . print ( GcdOfArray ( arr , 0 ) + "NEW_LINE"); int [ ] arr1 = { 2 , 4 , 6 , 8 } ; System . out . print ( GcdOfArray ( arr1 , 0 ) + "NEW_LINE"); } }