C语言 结构体:求空间两点的距离。下面这段代码,编译能通过,可是数据不...

发布网友 发布时间:2024-10-23 21:54

我来回答

1个回答

热心网友 时间:2024-10-26 01:39

# include <stdio.h>
# include <math.h>
struct Point
{
double x;
double y;
double z;
};
double distance(struct Point p1,struct Point p2)
{
double d;
struct Point c;
c.x = (p1.x-p2.x)*(p1.x-p2.x);
c.y = (p1.y-p2.y)*(p1.y-p2.y);
c.z = (p1.z-p2.z)*(p1.z-p2.z);
d = sqrt(c.x+c.y+c.z);
return d;
}
void main ()
{
struct Point p1,p2;
double dis;
printf("Input:\n");
scanf("%lf%lf%lf",&p1.x,&p1.y,&p1.z);
scanf("%lf%lf%lf",&p2.x,&p2.y,&p2.z); //&lf 写错了吧
dis = distance(p1,p2);
printf("%.3lf\n",dis);
}
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com