- #include <iostream>
- #include <math.h>
- using namespace std;
- // 计算二维平面上随机两个点的坐标
- void compute(float x1, float y1, float x2, float y2)
- {
- // sqrt()是 math.h 头文件中求开平方根的函数, abs()是 math.h 头文件中求绝对值的函数
- float distance = sqrt(abs((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
- printf("(%f,%f)与 (%f,%f) 两点之间的距离是:%f", x1, y1, x2, y2, distance);
- }
- int main()
- {
- float x1, y1, x2, y2;
- cin>> x1>> y1>> x2>> y2;
- compute(x1, y1, x2, y2);
- return 1;
- }
来源: http://www.bubuko.com/infodetail-3365454.html