Mr_ZLH @ 2020-11-03 17:54:22
#include <stdio.h>
#include <math.h>
double dis(double a,double b,double c,double d)
{
int l;
l=sqrt((c-a)*(c-a)+(d-b)*(d-b));
return (l);
}
int main()
{
double dis(double a,double b,double c,double d);
double x1,y1,x2,y2,x3,y3;
double i;
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
i=dis(x1,y1,x2,y2)+dis(x2,y2,x3,y3)+dis(x1,y1,x3,y3);
printf("%.2lf",i);
return 0;
}
by ud2_ @ 2020-11-03 18:10:20
hypot
是给出直角边求斜边;return
,不要出现像 int l
这样的错误;dis
已经定义过,就不用再在 main
里声明了。 #include <stdio.h>
#include <math.h>
double dis(double a,double b,double c,double d)
{
- int l;
- l=sqrt((c-a)*(c-a)+(d-b)*(d-b));
- return (l);
-
+ return hypot(c - a, d - b);
}
int main()
{
- double dis(double a,double b,double c,double d);
double x1,y1,x2,y2,x3,y3;
double i;
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
i=dis(x1,y1,x2,y2)+dis(x2,y2,x3,y3)+dis(x1,y1,x3,y3);
printf("%.2lf",i);
return 0;
-
}
by Cander花朵 @ 2020-11-03 18:16:22
double dis\ 结果返回了个int?
by Mr_ZLH @ 2020-11-03 22:34:58
@sjx233_ 感谢大佬,过了。