计算两个坐标点之间的距离
<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
0 1 1 0
Sample Output
1.00
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);}}
还没有评论,来说两句吧...