acm 两点距离

两点距离

时间限制:3000 ms  |  内存限制:65535 KB

难度:1

输入

第一行输入一个整数n(0<n<=1000),表示有n组测试数据;
随后每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。

输出

对于每组输入数据,输出一行,结果保留两位小数。

样例输入

2
0 0 0 1
0 1 1 0

样例输出

1.00
1.41

描述

输入两点坐标(X1,Y1),(X2,Y2)(0<=x1,x2,y1,y2<=1000),计算并输出两点间的距离。

扫描二维码关注公众号,回复: 2540921 查看本文章

#include<stdio.h>
#include<math.h>           //调用数学函数

void Distance_two(float x,float y,float x1,float y1){
 float distance;
 
 float x_distance = fabs(x - x1);
 float y_distance = fabs(y - y1);
 distance = float(pow(x_distance,2)) + float(pow(y_distance,2));
 
 printf("%.2f\n",float(sqrt(distance)));
}

int main(){
 int n;
 float x,y,x1,y1;
 scanf("%d",&n);
 while(n--){
  scanf("%f%f%f%f",&x,&y,&x1,&y1);
  Distance_two(x,y,x1,y1);
 }
}

猜你喜欢

转载自blog.csdn.net/chen1042246612/article/details/81287455