⼀*【问题描述】要求定义和调用函数dist(x1, y1, x2,y2)计算两点 间的距离懿

2024-11-26 07:48:27
推荐回答(1个)
回答1:

/*来试一试下面的。dist函数的类型应定义成double型,不能是int型。*/

#include
#include
double dist(double x1,double x2,double y1,double y2)
{
double distance;
distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
return distance;
}
int main(void)
{
double x1,x2,y1,y2,distance;
printf("Input(x1,y1): ");
scanf("%lf %lf",&x1,&y1);
printf("Input(x2,y2): ");
scanf("%lf %lf",&x2,&y2);
distance=dist(x1,x2,y1,y2);
printf("distance=%.2f,%f\n",distance,a);
return 0;
}