Find the final number obtained after performing the given operation | C ++ implementation of the approach ; Function to return the final number obtained after performing the given operation ; Find the gcd of the array elements ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int finalNum ( int arr [ ] , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { result = __gcd ( result , arr [ i ] ) ; } return result ; } int main ( ) { int arr [ ] = { 3 , 9 , 6 , 36 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << finalNum ( arr , n ) ; return 0 ; }