EkSulfur @ 2023-08-16 21:29:58
求教大佬
#include<stdio.h>
#include<math.h>
double dis(double x,double y,double u,double v);
int main(void){
double x[3],y[3];
double l;
for(int i=0;i<3;i++){
scanf("%lf%lf",&x[i],&y[i]);
}
l=dis(x[0],y[0],x[1],y[1])+dis(x[0],y[0],x[2],y[2])+dis(x[1],y[1],x[2],y[2]);
printf("%.2lf",l);
return 0;
}
double dis(double x,double y,double u,double v){
int ans=sqrt(pow(x-u,2)+pow(y-v,2));
return ans;
}
by KarmaticEnding @ 2023-08-16 21:47:56
《int ans》
by KarmaticEnding @ 2023-08-16 21:49:23
@EkSulfur
由于sqrt()
返回double
型,所以int ans
是错误的,应该改成double ans
by KarmaticEnding @ 2023-08-16 21:51:08
#include<bits/stdc++.h>
using namespace std;
double dis(double x,double y,double u,double v);
int main(){
double x[3],y[3];
double l;
for(int i=0;i<3;i++){
cin>>x[i]>>y[i];
}
l=dis(x[0],y[0],x[1],y[1])+dis(x[0],y[0],x[2],y[2])+dis(x[1],y[1],x[2],y[2]);
printf("%.2f",l);
return 0;
}
double dis(double x,double y,double u,double v){
double ans=sqrt(pow(x-u,2)+pow(y-v,2));
return ans;
}
AC代码
by EkSulfur @ 2023-08-16 21:51:28
@light_dream 谢谢指正