c语言求助

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

zhaoanqiEtayo @ 2023-07-26 14:31:21

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    double x1,x2,x3,y1,y2,y3,dis1,dis2,dis3,ans;
    scanf("%lf %lf\n%lf %lf\n%lf %lf\n",&x1,&y1,&x2,&y2,&x3,&y3);
    dis1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    dis2=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
    dis3=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    ans=dis1+dis2=dis3;
    printf("%.2lf",ans);
    return 0;
}

by rnf5114 @ 2023-07-26 14:41:12

@zhaoanqiEtayo

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    double x1,x2,x3,y1,y2,y3,dis1,dis2,dis3,ans;
    scanf("%lf %lf\n%lf %lf\n%lf %lf\n",&x1,&y1,&x2,&y2,&x3,&y3);
    dis1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    dis2=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
    dis3=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    ans=dis1+dis2+dis3;
    printf("%.2lf",ans);
    return 0;
}

|