616.The distance between two points

616.The distance between two points

Given two points P1 and P2, where the coordinates of P1 are (x1, y1) and the coordinates of P2 are (x2, y2), please calculate the distance between the two points.

Input format

There are two lines of input, each line contains two double-precision floating-point numbers xi, yi, which represent the coordinates of one of the points.

All input values ​​are kept to one decimal place.

Output format

Output your result, keeping four decimal places.

data range

−109≤xi,yi≤109

Input sample:

1.0 7.0
5.0 9.0

Sample output:

4.4721
/* 总结常用的 <cmath> 函数:
平方 pow( , 2)
开方 pow( , 0.5)、sqrt( )
整数绝对值 abs( )
浮点数绝对值 fabs( ) */


#include <cstdio>
#include <cmath>

int main()
{
	double x1, y1, x2, y2;
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%.4lf\n", sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
	
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_42465670/article/details/114558374