Iterate through all pairs
for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) { int number = stoi ( getNumber ( arr [ i ] , arr [ j ] ) ) ; largest = max ( largest , number ) ; } cout << largest ; }