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

1个回答

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

    #include

    #include

    double dist(double x1,double x2,double y1,double y2)

    {

    x09double distance;

    x09x09distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

    x09x09return distance;

    x09}

    int main(void)

    x09{

    x09x09double x1,x2,y1,y2,distance;

    x09x09x09printf("Input(x1,y1):");

    x09x09x09scanf("%lf %lf",&x1,&y1);

    x09x09x09printf("Input(x2,y2):");

    x09x09x09scanf("%lf %lf",&x2,&y2);

    x09x09x09distance=dist(x1,x2,y1,y2);

    x09x09x09printf("distance=%.2f,%fn",distance,a);

    x09x09x09return 0;

    x09x09}