Distance Between Points
I need some help. I have to create a function that will calculate the distance between points (x1,y1) and (x2, y2). All numbers are of type double. I keep getting incorrect output. I am usinge visual studio and C language. Here is my code.
#include <stdio.h>
#include <math.h> double calculate_distance (double x1,double y1,double x2 ,double y2) { double distance; double distance_x = x1-x2; double distance_y = y1- y2; distance = sqrt( (distance_x * distance_x) + (distance_y * distance_y)); return distance; } int main ()
{
double x1; double x2; double y1; double y2; printf ("Let me help you find the distance between two points (x1,y1) and (x2, y2)."); printf ("\n\nEnter coordinate for x1:");
scanf ("%f", &x1); printf ("\nEnter coordinate for y1:");
scanf ("%f", &y1); printf ("\nEnter coordinate for x2:");
scanf ("%f", &x2); printf ("\nEnter coordinate for y2:");
scanf ("%f", &y2); printf ("The distance between (%f,%f) and (%f,%f) is %.2f\n\n", x1,y1,x2,y2, calculate_distance(x1,y1,x2,y2)); return ; }
Distance Between Points的更多相关文章
- 【BZOJ】3053: The Closest M Points(kdtree)
http://www.lydsy.com/JudgeOnline/problem.php?id=3053 本来是1a的QAQ.... 没看到有多组数据啊.....斯巴达!!!!!!!!!!!!!!!! ...
- 数据结构(KD树):HDU 4347 The Closest M Points
The Closest M Points Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Ot ...
- HDU 4347 - The Closest M Points - [KDTree模板题]
本文参考: https://www.cnblogs.com/GerynOhenz/p/8727415.html kuangbin的ACM模板(新) 题目链接:http://acm.hdu.edu.cn ...
- The Closest M Points
The Closest M Points http://acm.hdu.edu.cn/showproblem.php?pid=4347 参考博客:https://blog.csdn.net/acdre ...
- 【BZOJ】【3053】The Closest M Points
KD-Tree 题目大意:K维空间内,与给定点欧几里得距离最近的 m 个点. KD树啊……还能怎样啊……然而扩展到k维其实并没多么复杂?除了我已经脑补不出建树过程……不过代码好像变化不大>_&g ...
- BZOJ 3053: The Closest M Points(K-D Tree)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1235 Solved: 418[Submit][Status][Discuss] Descripti ...
- BZOJ3053:The Closest M Points(K-D Teee)
Description The course of Software Design and Development Practice is objectionable. ZLC is facing a ...
- Geographical distance
Introduction Calculating the distance between geographical coordinates is based on some level of abs ...
- 【35.43%】【hdu 4347】The Closest M Points
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 98304/98304 K (Java/Others) Total Submissio ...
随机推荐
- 支付宝Cookie高危漏洞引发的思考
背景:当时我在做公司的网站支付接入,在调试支付宝WAP支付时,发现一些匪夷所思的事情: 1.我想要切换账号时退到需要输入登录信息时,原账号并没有退出,我按一下后退键又回来了: 2.我关闭浏览器也没有退 ...
- strlen 与 sizeof 的区别
void ngx_time_init(void) { ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1 ...
- sockaddr与sockaddr_in结构体简介
struct sockaddr { unsigned short sa_family; /* address family, AF_xxx */char sa_data[14]; ...
- MATLAB 中NORM运用
格式:n=norm(A,p)功能:norm函数可计算几种不同类型的矩阵范数,根据p的不同可得到不同的范数 以下是Matlab中help norm 的解释 NORM Matrix or vector ...
- js正则表单验证汇总,邮箱验证,日期验证,电话号码验证,url验证,信用卡验证,qq验证
本文主要汇总各种正则验证,很多都是转载,本人也会尽可能验证准确性,如有错误欢迎留言 //trim()方法在有些浏览器中不兼容,最好自己重写一下 String.prototype.trim=functi ...
- extjs基础 使用图标字体来美化按钮)
下载 Font Awesome 1.拷贝css 和 fonts 到build同级目录 2.需要在index.html中引入css文件 3.在main.js文件中添加 initComponent : f ...
- 在Winform中播放视频等【DotNet,C#】
在项目中遇到过这样的问题,就是如何在Winform中播放视频.当时考察了几种方式,第一种是直接使用Windows Media Player组件,这种最简单:第二种是利用DirectX直接在窗体或者控件 ...
- mysql 创建索引
完整版创建索引如下:CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name [index_type] ON tbl_name (index_col_name ...
- 【POJ 1556】The Doors 判断线段相交+SPFA
黑书上的一道例题:如果走最短路则会碰到点,除非中间没有障碍. 这样把能一步走到的点两两连边,然后跑SPFA即可. #include<cmath> #include<cstdio> ...
- Struts2 Action扩展名的三种修改方法
最近在做项目开发过程中犯了一个很低级的错误,在这里列举出来,供大家参考借鉴:我希望通过Url请求一个Action,最终通过服务器的处理能得到一个Json串,所以我在Url中体现这一特点,将action ...