本题要求实现一个函数,对给定平面任意两点坐标(x1,y1)和(x2,y2),求这两点之间的距离。
double dist( double x1, double y1, double x2, double y2 );
其中用户传入的参数为平面上两个点的坐标(x1
, y1
)和(x2
, y2
),函数dist
应返回两点间的距离。
#include
#include
double dist(double x1, double y1, double x2, double y2)
{
double Pow,dist;
Pow=pow((y2 - y1), 2) + pow((x2 - x1), 2);
dist=sqrt(Pow);
return dist;
}
int main()
{
double x1, y1, x2, y2;
scanf_s("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
printf_s("dist = %.2f\n", dist(x1, y1, x2, y2));
return 0;
getchar();
}