计算两点之间距离的C程序

计算两点之间距离的c程序

给定两点坐标,任务是找到两点之间的距离并显示结果。

在二维平面中有两个点,假设 A 和 B 具有各自的坐标作为 (x1, y1) 和 (x2, y2) 并计算它们之间的距离,有一个直接公式,如下所示

$$sqrt{lgroup x2-x1rgroup^{2 }+lgroup y2-y1rgroup^{2}}$$

下面是表示两点及其差异的图表

$$ frac{(x_2-x_1)}{(x_1,y_1)::::::(y_2-y_1)::::::(x_2,y_2)} $$

下面使用的方法如下

输入坐标为x1、x2、y1和y2应用公式计算两点之间的差异打印距离

算法

StartStep 1-> declare function to calculate distance between two point   void three_dis(float x1, float y1, float x2, float y2)      set float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0)      print disstep 2-> In main()   Set float x1 = 4   Set float y1 = 9   Set float x2 = 5   Set float y2 = 10   Call two_dis(x1, y1, x2, y2)Stop

示例

#include #include//function to find distance bewteen 2 pointsvoid two_dis(float x1, float y1, float x2, float y2) {   float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);   printf("Distance between 2 points are : %f", dis);   return;}int main() {   float x1 = 4;   float y1 = 9;   float x2 = 5;   float y2 = 10;   two_dis(x1, y1, x2, y2);   return 0;}

输出

如果我们运行上述代码,它将生成以下输出

Distance between 2 points are : 1.414214

以上就是计算两点之间距离的C程序的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444772.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月17日 21:51:53
下一篇 2025年12月11日 06:18:45

发表回复

登录后才能评论
关注微信