码迷,mamicode.com
首页 > 编程语言 > 详细

武汉科技大学ACM :1006: 零起点学算法25——求两点之间的距离

时间:2014-12-09 22:44:56      阅读:408      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   sp   strong   on   数据   

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

 1 #include<stdio.h>
 2 
 3 #include<math.h>
 4 
 5  
 6 
 7 int main()
 8 
 9 {
10 
11          float x1,y1,x2,y2;
12 
13          double len;
14 
15          while(scanf("%f%f%f%f",&x1,&y1,&x2,&y2)!=EOF)
16 
17          {
18 
19                    len=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
20 
21                    printf("%.2lf\n",len);
22 
23          }
24 
25                    return 0;
26 
27 }

其他代码:

 1 #include<stdio.h>
 2 #include<math.h>
 3 int main()
 4 {
 5     double x1,x2,y1,y2;
 6     double distance;
 7     while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
 8     {
 9         distance=sqrt(fabs(x1-x2)*fabs(x1-x2)+fabs(y1-y2)*fabs(y1-y2));
10         printf("%.2lf\n",distance);
11     }
12     return 0;
13 }

 

武汉科技大学ACM :1006: 零起点学算法25——求两点之间的距离

标签:des   style   blog   io   color   sp   strong   on   数据   

原文地址:http://www.cnblogs.com/liuwt365/p/4154142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!