#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
double x1,y1,x2,y2,x3,y3;
double x,y;
double distance1;
double distance2;
double distance3;
printf("请分别输入x1,y1坐标并以空格隔开:\n");
while(cin >> x1 >> y1 >> x >> y){
distance1 = sqrt(pow(x-x1, 2) + pow(y1-y, 2));
cout << setprecision(2) << fixed << distance1 << endl;
printf("第一个坐标(x1,y1)到待定位传感器节点坐标(x,y)的距离:distance1=%lf\n",distance1);
break;
}
printf("请分别输入x2,y2坐标并以空格隔开输入完两个坐标按回车进入下一个计算距离:\n",x2,y2);
while(cin >> x2 >> y2 >> x >> y){
distance2 = sqrt(pow(x-x2, 2) + pow(y-y2, 2));
cout << setprecision(2) << fixed << distance2 << endl;
printf("第二个坐标(X2,x2)到待定位传感器节点坐标(x,y)的距离:distance2=%lf\n",distance2);
break;
}
printf("请分别输入x3,y3坐标并以空格隔开:\n",x3,y3);
while(cin >> x3 >> y3 >> x >> y){
distance2 = sqrt(pow(x-x3, 2) + pow(y-y3, 2));
cout << setprecision(2) << fixed << distance2 << endl;
printf("第个坐标(x3,x3)到待定位传感器节点坐标(x,y)的距离:distance3=%lf\n",distance3);
break;
}
return 0;
}
|