1118: 零起点学算法25——求两点之间的距离

亦凉 2023-01-10 13:10 538阅读 0赞

Description

输入平面坐标系中2点的坐标,输出它们之间的距离

Input

输入4个浮点数x1 y1 x2 y2,分别是点(x1,y1) (x2,y2)的坐标(多组数据)

Output

输出它们之间的距离,保留2位小数(每组数据一行)

" class="reference-link">Sample Input 5f8f312f51791b8bb0ed0ae07c2ffa43.gif

  1. 1 0 2 0

Sample Output

  1. 1.00

Source

零起点学算法

Code

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<iomanip>
  4. #include<math.h>
  5. using namespace std;
  6. int main()
  7. {
  8. float x1,x2,y1,y2;
  9. while(~scanf("%f%f%f%f",&x1,&y1,&x2,&y2))
  10. {
  11. float ans=0;
  12. ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
  13. printf("%.2f\n",ans);
  14. }
  15. }

发表评论

表情:
评论列表 (有 0 条评论,538人围观)

还没有评论,来说两句吧...

相关阅读