两点间距离公式全部(计算两点之间的距离)
两点间距离公式全部(计算两点之间的距离){double distance(double x1 double y1 double x2 double y2)*/#include<stdio.h>#include<math.h>
/*
函数参数:传入两点坐标
函数功能:计算平面上,两点之间的距离
返回值:返回两点之间的距离
*/
#include<stdio.h>
#include<math.h>
double distance(double x1 double y1 double x2 double y2)
{
double side1 side2 distance;
side1=fabs(x1-x2);
side2=fabs(y1-y2);
distance=sqrt(side1*side1 side2*side2);
return distance;
}
int main()
{
double x1 y1 x2 y2;
double distan;
printf("分别输入坐标x1 y1 x2 y2\n");
scanf("%lf%lf%lf%lf" &x1 &y1 &x2 &y2);
distan=distance(x1 y1 x2 y2);
printf("点(%.2lf %.2lf)到点(%.2lf %.2lf)距离为:\n%.2lf\n" x1 y1 x2 y2 distan);
getchar();
return 0;
}