给定 A(x_1, y_1)A(x1,y1),B(x_2, y_2)B(x2,y2) 两点坐标,计算它们间的距离。
一、代码展示
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double x1,y1,x2,y2,d;
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
d=pow(x1-x2, 2) + pow(y1-y2, 2);
d=sqrt(d);
printf("%.2lf",d);
return 0;
}
二、代码解释
三、结果展示