LCM of given array elements |  ; Function to return gcd of a and b ; recursive implementation ; lcm ( a , b ) = ( a * b / gcd ( a , b ) ) ; Driver code
using System ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } static int LcmOfArray ( int [ ] arr , int idx ) { if ( idx == arr . Length - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = LcmOfArray ( arr , idx + 1 ) ; return ( a * b / __gcd ( a , b ) ) ; } static void Main ( ) { int [ ] arr = { 1 , 2 , 8 , 3 } ; Console . WriteLine ( LcmOfArray ( arr , 0 ) ) ; int [ ] arr1 = { 2 , 7 , 3 , 9 , 4 } ; Console . WriteLine ( LcmOfArray ( arr1 , 0 ) ) ; } }