计算两点间的距离
来源:互联网 发布:mac 的火箭按钮不见了 编辑:程序博客网 时间:2024/05/16 17:15
计算两点间的距离
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
Sample Input
0 0 0 1
0 1 1 0
Sample Output
1.00
1.41
注意事项:
scanf中,char对应%c(单个字符)或%s(字符数组);string对应%s;int对应%d;long long int对应%lld;float对应%f;double对应lf。
int的范围是2*10^9(32位),long long int是10^18(64位);
double比float更常用。
代码:
#include<iostream>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<memory.h>#include<algorithm>using namespace std;int main(){ //因为输入的是实数,故要用double或float来定义 double x1,y1,x2,y2; while(scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2)!=EOF) { /*C语言中,math.h文件中含有乘方(包括开方)的库函数,是pow(x,y) 其中x和y都是双精度浮点(double)型,x是底数,y是指数(如果是小数即为开方); sqrt()函数是开平方根*/ double sum; double a=pow((x1-x2),2)+pow((y1-y2),2); sum=pow(a,0.50); //或写成sum=sqrt(a); 注意由于结果要保留两位小数,故是0.50而不是0.5 printf("%.2lf\n",sum); //保留一位小数的写法为printf("%.1lf\n",sum);"."后面的第一个是数字1,第二个是小写字母l } return 0;}
阅读全文
0 0
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 计算两点间的距离
- 2001 计算两点间的距离
- hdu 2001 计算两点间的距离
- 1001 计算两点间的距离
- HDU 2001 计算两点间的距离
- 2001 计算两点间的距离
- C#计算两点间的距离
- Python中的闭包
- 按位定义结构体
- JDK8的ParallelStream遍历无序的问题
- 倒计时时钟 面向对象
- html标签
- 计算两点间的距离
- Collection集合之操作元素方法实现
- 为什么不要把ZooKeeper用于服务发现?
- 基于链表的栈实现
- [JavaEE
- C#中的MessageBox消息对话框
- 开启本地内核调试
- 高斯消元求解模线性方程-poj2947
- java数组和Object关系