哪里错了

P5735 【深基7.例1】距离函数

cht3362733140 @ 2024-10-31 23:34:30

#include<stdio.h>
#include<math.h>
double dis(double x1,double x2,double y1,double y2);
int main()
{
    double x1,x2,x3,y1,y2,y3,ab,ac,bc,s;
    scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
    ab=dis(x1,y1,x2,y2);
    ac=dis(x1,y1,x3,y3);
    bc=dis(x2,y2,x3,y3);
    s=ab+ac+bc;
    printf("%.2lf",s);
    return 0;
}
double dis(double x1,double x2,double y1,double y2)
{
    double s;
    s=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    s=sqrt(s);
    return s;
}

by NiuNiu20121219 @ 2024-10-31 23:51:44

你的dis函数参数是不是填错了?你在主函数里调用时是写的x1, y1, x2, y2。但是在dis函数里你写的是x1, x2, y1, y2。


by NiuNiu20121219 @ 2024-10-31 23:52:59

double dis(double x1,double y1,double x2,double y2)
{
    double s;
    s=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    s=sqrt(s);
    return s;
}

dis函数应该是这样吧


|