1118: 零起点学算法25——求两点之间的距离
Description
输入平面坐标系中2点的坐标,输出它们之间的距离
Input
输入4个浮点数x1 y1 x2 y2,分别是点(x1,y1) (x2,y2)的坐标(多组数据)
Output
输出它们之间的距离,保留2位小数(每组数据一行)
" class="reference-link">Sample Input 
1 0 2 0
Sample Output
1.00
Source
零起点学算法
Code
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
float x1,x2,y1,y2;
while(~scanf("%f%f%f%f",&x1,&y1,&x2,&y2))
{
float ans=0;
ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
printf("%.2f\n",ans);
}
}
还没有评论,来说两句吧...