我不太了解该函数如何与structs概念一起使用。
有人可以解释或告诉我如何实现吗?
代码:
#include <stdio.h>
#include <math.h>
struct POINT {
double x;
double y;
};
double distance_of_points(struct POINT p1, struct POINT p2)
{
return sqrt(pow((POINT p1), 2) + pow((POINT p2), 2));
};
int main(void)
{
struct POINT X={1., 1.}, Y={2., 2.}, Z={-2., -1};
printf("Die Entfernung von X und Y betraegt: %.2f\n", distance_of_points(X, Y) );
printf("Die Entfernung von X und Z betraegt: %.2f\n", distance_of_points(X, Z) );
printf("Die Entfernung von Y und Z betraegt: %.2f\n", distance_of_points(Z, Y) );
return 0;
}
答案 0 :(得分:1)
double distance_of_points(struct POINT p1, struct POINT p2)
{
return sqrt(pow((p1.x - p2.x), 2) + pow((p1.y - p2.y), 2));
};
打开编译器警告!