C/C++標準ライブラリで2点間距離 (x1,y1) - (x2,y2) を計算する方法。C99以降またはC++11以降では、sqrt関数の他にhypot関数も利用できる。*1 #include <cmath> // C++98 double dist = std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); // C++11以降 double dist = std::hypot(x2 - x1, y2 - y1); #include <math.h> /* C90 */ double dist = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); // C99以降 double dist = hypot(x2 - x1, y2 - y1); メモ:hypotは三平方の定理