您的位置:首页 > 其它

2001

2016-03-27 13:40 218 查看
计算2点之间的距离

#include <stdio.h>
#include <math.h>
int mydistance(int a,int b,int c,int d);
int main()
{
char buff[8];
int buffer[4];
while(gets(buff))
{
buffer[0] = buff[0] - '0';
buffer[1] = buff[2] - '0';
buffer[2] = buff[4] - '0';
buffer[3] = buff[6] - '0';
printf("%d\n",mydistance(buffer[0],buffer[1],buffer[2],buffer[3]));
}
return 0;
}

int mydistance(int a,int b,int c,int d)
{
int e;
e = sqrt((c - a)*(c - a) + (d - b)*(d - b));
return e;
}


参考c++

#include <cmath>
#include <cstdio>

int main(void)
{
double x[2], y[2];

while (scanf("%lf%lf%lf%lf", x, y, x+1, y+1) != EOF)
printf("%.2f\n", sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0])));

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: