您的位置:首页 > 其它

问题一百三十七:计算坐标上两点之间的距离

2013-05-14 20:38 323 查看


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float distance(int a, int b, int c, int d);

int main(int argc, char *argv[])
{
int a;
int b;
int c;
int d;

printf("Please enter the first coordinate points x:");     //输入第一个点
scanf("%d %d", &a, &b);
printf("Please enter the second coordinate points y:");    //输入第二个点
scanf("%d %d", &c, &d);

printf("The distance between two points is %f\n", distance(a, b, c, d));

system("PAUSE");
return 0;
}

// Calculate distances

float distance(int a, int b, int c, int d)     //计算两点的距离
{
int   x;
int   y;
float distance;

x=abs(a-c);
y=abs(b-d);
distance=sqrt(x*x+ y*y);

return distance;
}


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