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 ...
随机推荐
- PRML读书会第七章 Sparse Kernel Machines(支持向量机, support vector machine ,KKT条件,RVM)
主讲人 网神 (新浪微博: @豆角茄子麻酱凉面) 网神(66707180) 18:59:22 大家好,今天一起交流下PRML第7章.第六章核函数里提到,有一类机器学习算法,不是对参数做点估计或求其分 ...
- mvc5+ef6+Bootstrap 项目心得--创立之初
1.mvc5+ef6+Bootstrap 项目心得--创立之初 2.mvc5+ef6+Bootstrap 项目心得--身份验证和权限管理 3.mvc5+ef6+Bootstrap 项目心得--WebG ...
- [Python]新手写爬虫全过程(已完成)
今天早上起来,第一件事情就是理一理今天该做的事情,瞬间get到任务,写一个只用python字符串内建函数的爬虫,定义为v1.0,开发中的版本号定义为v0.x.数据存放?这个是一个练手的玩具,就写在tx ...
- 学习SQLite之路(二)
下面就是真正关于数据库的一些知识了: 20160614更新 参考: http://www.runoob.com/sqlite/sqlite-tutorial.html 1. SQLite创建表: 基本 ...
- EmitMapper的使用
1.普通的映射. public class UserInfo { public int id { get; set; } public string name { get; set; } public ...
- C# WinForm应用程序降低系统内存占用方法
这里整理了一些网上关于Winform如何降低系统内存占用的资料,供参考: 1.使用性能测试工具dotTrace 3.0,它能够计算出你程序中那些代码占用内存较多2.强制垃圾回收3.创建完对象实例后,记 ...
- IQueryable和list本地集合区别
详情请看:http://www.cnblogs.com/imust/archive/2012/11/18/2776320.html
- 东大OJ-1391-Big big Power
题目描述 Calculate the power num a^(b^c) mod 1e9+7 输入 Multiple test cases,each case has three integers a ...
- 北大OJ 1001题
题目:输入一序列的正实数和幂次(正整数)对,然后打印结果(具体的比这个精细) 这道题是关于大数计算的(大数求幂),从开始建立思路,到写代码.调式到最后被AC以及最终的优化,总共用了差不多一天的时间.开 ...
- 二叉树的建立与递归遍历C语言版
</pre><pre name="code" class="cpp">#include <stdio.h> #include ...