定义如下点结构类型
typedef struct
{
double x, y;
} POINT;
说明:x和y分别为点的横坐标和纵坐标。
下面的程序输入两个点坐标,求两点间的距离并输出。
#include <stdio.h>
#include <math.h>
typedef struct
{
double x, y;
} POINT;
int main()
{
POINT a, b;
double s, p, q;
scanf("%lf %lf", &a.x, &a.y);
scanf("%lf %lf", &b.x, &b.y);
/* 你提交的代码将被嵌在这里 */
printf("%g\n", s);
return 0;
}
输入样例:
-8.5 6.4 3.7 -1.2 |
输出样例:
14.3736 |
作答:
p=(a.x-b.x)*(a.x-b.x);
q=(b.y-a.y)*(b.y-a.y);
s=sqrt(q+p);