计算二维平面上随机两个点的坐标

#include <iostream>
#include <math.h>
using namespace std;

//计算二维平面上随机两个点的坐标
void compute(float x1, float y1, float x2, float y2)
{

  // sqrt()是math.h头文件中求开平方根的函数,abs()是math.h头文件中求绝对值的函数
  float distance = sqrt(abs((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
  printf("(%f,%f)与(%f,%f)两点之间的距离是:%f", x1, y1, x2, y2, distance);
}

int main()
{
  float x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  compute(x1, y1, x2, y2);
  return 1;
}

在本博客上的内容全部共享公开不收费 转载请注明出处,尊重知识,尊重劳动 对代码或者知识有疑问,可联系博主(qq):2218787597(或邮件投递)
原文地址:https://www.cnblogs.com/TyranRex/p/12149628.html