Problem Description
输入平面坐标系中2点的坐标,输出它们之间的距离
Input
输入4个浮点数x1 y1 x2 y2,分别是点(x1,y1) (x2,y2)的坐标(多组数据)
Output
输出它们之间的距离,保留2位小数(每组数据一行)
Sample Input
1 0 2 0
Sample Output
1.00
#include<stdio.h> #include<math.h> int main() { float x1,y1,x2,y2; double len; while(scanf("%f%f%f%f",&x1,&y1,&x2,&y2)!=EOF) { len=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); printf("%.2lf\n",len); } return ; }
其他代码:
#include<stdio.h>
#include<math.h>
int main()
{
double x1,x2,y1,y2;
double distance;
while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
{
distance=sqrt(fabs(x1-x2)*fabs(x1-x2)+fabs(y1-y2)*fabs(y1-y2));
printf("%.2lf\n",distance);
}
return ;
}