[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;
}