【题目描述】

已知线段的两个端点的坐标A(,B(),求线段AB的长度,保留到小数点后3位。

【输入】

第一行是两个实数,即A的坐标。

第二行是两个实数,即B的坐标。

输入中所有实数的绝对值均不超过10000

【输出】

一个实数,即线段AB的长度,保留到小数点后3位。

【输入样例】

1
2
1 1 2 2

【输出样例】

1
1.414

解:

1
2
3
4
5
6
7
8
9
10
#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; }

发表评论