- generate random numbers
- sort collections
- find the minimum value of a function of pair of (different) values belonging to a collection.

You may also try the following code:

C++

#include <iostream> #include <tuple> #include <vector> #include <random> #include <algorithm> #include <limits> using namespace std; using Point = tuple<double, double>; double generate_scaled( mt19937 & generator ); double distance( const Point & p1, const Point & p2); int main() { mt19937 generator{}; vector < Point > vpoint; while ( vpoint.size() < 100) { vpoint.emplace_back( make_tuple<double, double>( generate_scaled(generator), generate_scaled(generator) ) ); } sort(vpoint.begin(), vpoint.end(), [](const Point & p1, const Point & p2) { return get<0>(p1) < get<0>(p2); } ); double min_i, min_j; double min_distance = numeric_limits<double>::max(); for (size_t i=0; i<vpoint.size()-1; ++i) for (size_t j=i+1; j<vpoint.size(); ++j) { auto d = distance( vpoint[i], vpoint[j]); if ( min_distance > d) { min_distance = d; min_i = i; min_j = j; } } for (const auto & t : vpoint) cout << get<0>(t) << ", " << get<1>(t) << endl; cout << "closest points are\n"; cout << "p[" << min_i << "] = (" << get<0>(vpoint[min_i]) << "," << get<1>(vpoint[min_i]) << ")\n"; cout << "p[" << min_j << "] = (" << get<0>(vpoint[min_j]) << "," << get<1>(vpoint[min_j]) << ")\n"; cout << "with distance = " << sqrt(min_distance) << endl; } double generate_scaled( mt19937 & generator ) { double x = generator(); x = 1.0 + (x - generator.min()) * 99.0 / (generator.max() - generator.min()); return x; } double distance( const Point & p1, const Point & p2) { double dx = get<0>(p1)-get<0>(p2); double dy = get<1>(p1)-get<1>(p2); return (dx*dx + dy*dy); }

Try writing code to do that and we'll help you as we can. We will not write that for you though as you will learn little if we do.