一本通1033:计算线段长度

题目传送门

【题目描述】

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

【输入】

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

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

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

【输出】

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

【输入样例】

1 1
2 2

【输出样例】

1.414

分析:

运用到的知识点有两点之间距离公式:

Code:

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<fixed<<setprecision(3)<<sqrt(pow((x1-x2),2)+pow((y1-y2),2));
	return 0;
}
posted @ 2020-06-16 20:04  _pwl  阅读(1146)  评论(1编辑  收藏  举报
1 2 3
4