A. 求C语言程序:计算两点间的距离
代码如下:
#include<stdio.h>
#include<math.h>
struct point
{
double x;
double y;
};
struct point readPoint();
double distance(struct point p1,struct point p2);
int main(void)
{
struct point a,b;
double dis;
printf(" distance! ");
printf("please input the point(for example:1.0,2.0):");
a=readPoint();
printf(" please input the point(for example:1.0,2.0):");
b=readPoint();
dis=distance(a,b);
printf(" the distance is:%.2f ",dis);
return 0;
}
struct point readPoint()
{
struct point p;
scanf("%lf,%lf",&p.x,&p.y);
return p;
}
double distance(struct point p1,struct point p2)
{
double d;
d=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
return d;
}