首页 > 其他 > 详细

2001

时间:2016-03-27 14:07:17      阅读:173      评论:0      收藏:0      [点我收藏+]

 

 

计算2点之间的距离

 

 1 #include <stdio.h>
 2 #include <math.h>
 3 int mydistance(int a,int b,int c,int d);
 4 int main()
 5 {
 6     char buff[8];
 7     int buffer[4];
 8     while(gets(buff))
 9     {
10         buffer[0] = buff[0] - 0;
11         buffer[1] = buff[2] - 0;
12         buffer[2] = buff[4] - 0;
13         buffer[3] = buff[6] - 0;
14         printf("%d\n",mydistance(buffer[0],buffer[1],buffer[2],buffer[3]));
15     }
16     return 0;
17 }
18 
19 int mydistance(int a,int b,int c,int d)
20 {
21     int e;
22     e = sqrt((c - a)*(c - a) + (d - b)*(d - b));
23     return e;
24 }

 

参考c++

 1 #include <cmath>
 2 #include <cstdio>
 3 
 4 int main(void)
 5 {
 6     double x[2], y[2];
 7 
 8     while (scanf("%lf%lf%lf%lf", x, y, x+1, y+1) != EOF)
 9         printf("%.2f\n", sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0])));
10 
11     return 0;
12 }

 

2001

原文:http://www.cnblogs.com/ailx10/p/5325472.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!