计算线段长度
Description
已知线段的两个端点的坐标A(Xa,Ya),B(Xb,Yb),求线段AB的长度,保留到小数点后3位。
Input
第一行是两个实数Xa,Ya,即A的坐标。 第二行是两个实数Xb,Yb,即B的坐标。 输入中所有实数的绝对值均不超过10000。
Output
一个实数,即线段AB的长度,保留到小数点后3位。
Sample Input 1
1 1 2 2
Sample Output 1
1.414
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
double xa,ya,xb,yb,a,b,c;
cin>> xa >> ya >> xb >> yb;
a = fabs(xa-xb)
b = fabs(ya-yb)
c = sqrt(a*a+b*b)
cout << fixed << setprecision(3) << c;
return 0;
}