#include <stdio.h>
#include <math.h>
int main()
{
int x1,x2,y1,y2,d,dx,dy;
while (scanf("%d %d %d %d",&x1,&y1,&x2,&y2)!=EOF){
dx=x1-x2;
dy=y1-y2;
d=sqrt(dx*dx+dy*dy);
printf("%d
",d);
}
return 0;
}
题目说输出结果要是两位小数,而int是输入整型数,%d也是输出整型数
#include <stdio.h>
#include <math.h>
int main()
{
double x1,x2,y1,y2,d,dx,dy;
while (scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2)!=EOF){
dx=x1-x2;
dy=y1-y2;
d=sqrt(dx*dx+dy*dy);
printf("%.2lf
",d);
}
return 0;
}
float对应%f,double对应的%lf,输出%.2lf是保留两位小数