LCM of given array elements |  ; recursive implementation ; lcm ( a , b ) = ( a * b / gcd ( a , b ) ) ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int LcmOfArray ( vector < int > arr , int idx ) { if ( idx == arr . size ( ) - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = LcmOfArray ( arr , idx + 1 ) ; return ( a * b / __gcd ( a , b ) ) ; } int main ( ) { vector < int > arr = { 1 , 2 , 8 , 3 } ; cout << LcmOfArray ( arr , 0 ) << " STRNEWLINE " ; arr = { 2 , 7 , 3 , 9 , 4 } ; cout << LcmOfArray ( arr , 0 ) << " STRNEWLINE " ; return 0 ; }