问题一百三十七:计算坐标上两点之间的距离
[plain]
[plain]
[plain] #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;
}
补充:软件开发 , C语言 ,