【题目描述】
已知线段的两个端点的坐标A(,B(
),求线段
AB
的长度,保留到小数点后3
位。
【输入】
第一行是两个实数,即
A
的坐标。
第二行是两个实数,即
B
的坐标。
输入中所有实数的绝对值均不超过10000
。
【输出】
一个实数,即线段AB
的长度,保留到小数点后3
位。
【输入样例】
1 1
2 2
【输出样例】
1.414
解:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
double xa,ya,xb,yb,xcha,ycha,ans;
cin>>xa>>ya;
cin>>xb>>yb;
xcha=fabs(xa-xb);
ycha=fabs(ya-yb);
ans=sqrt(xcha*xcha+ycha*ycha);
printf("%.3lf",ans);
return 0;
}
最新回复