GCD of more than two ( or array ) numbers |  ; recursive implementation ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int GcdOfArray ( vector < int > & arr , int idx ) { if ( idx == arr . size ( ) - 1 ) { return arr [ idx ] ; } int a = arr [ idx ] ; int b = GcdOfArray ( arr , idx + 1 ) ; return __gcd ( a , b ) ; } int main ( ) { vector < int > arr = { 1 , 2 , 3 } ; cout << GcdOfArray ( arr , 0 ) << " STRNEWLINE " ; arr = { 2 , 4 , 6 , 8 } ; cout << GcdOfArray ( arr , 0 ) << " STRNEWLINE " ; return 0 ; }