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

#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;
}

猜你喜欢

转载自www.cnblogs.com/TyranRex/p/12149628.html
今日推荐