计算两个坐标点之间的距离

缺乏、安全感 2022-08-03 14:59 766阅读 0赞
  1. <span style="background-color: rgb(255, 255, 255);"> </span><div class="problem-widget"><div class="problem-widget-title">Problem Description</div><div class="problem-widget-content">输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。</div></div><div class="problem-widget"><div class="problem-widget-title">Input</div><div class="problem-widget-content">输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。</div></div><div class="problem-widget"><div class="problem-widget-title">Output</div><div class="problem-widget-content">对于每组输入数据,输出一行,结果保留两位小数。</div></div><div class="problem-widget"><div class="problem-widget-title">Sample Input</div><div class="problem-widget-content"><pre>0 0 0 1
  2. 0 1 1 0

Sample Output

  1. 1.00
  2. 1.41

#include “stdio.h”#include “math.h”double calculate(double x1 , double x2 ){double ds;ds = (x1-x2)*(x1-x2);return ds;}void main(){double x1,x2,y1,y2,ds1=0,ds2=0,result = 0 ;while( scanf(“%lf%lf%lf%lf”,&x1,&y1,&x2,&y2) != EOF ) {ds1 = calculate(x1,x2);ds2 = calculate(y1,y2);result = sqrt(ds1+ds2);printf(“%.2f\n”,result);}}

发表评论

表情:
评论列表 (有 0 条评论,766人围观)

还没有评论,来说两句吧...

相关阅读

    相关 根据经纬度坐标计算距离

    现在如果有个业务需求,就是要做一个根据定位坐标实现计算距离并找到附近的店铺的推荐功能,已知数据库中会存储店铺的经纬度坐标。那么,这个需求已经很明确了,在要求不高的情况下,只要计