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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int MinimumGCD ( int arr [ ] , int n ) { int g = 0 ; for ( int i = 0 ; i < n ; i ++ ) { g = __gcd ( g , arr [ i ] ) ; } return g ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 , 8 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << MinimumGCD ( arr , N ) << endl ; }