c语言中<math.h>头文件,计算两点之间的距离

c语言中<math.h>头文件,计算两点之间的距离。

<math.h>头文件包含基本数学函数的函数原型声明。

1、

#include <stdio.h>
#include <math.h>

double dist(double x1, double y1, double x2, double y2)
{
    return(sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
}

int main(void)
{
    double x1, y1, x2, y2;
    puts("please input the coordinates of the two points.");
    printf("point NO1, x1 = "); scanf("%lf", &x1);
    printf("           y1 = "); scanf("%lf", &y1);
    
    printf("point NO2, x2 = "); scanf("%lf", &x2);
    printf("           y2 = "); scanf("%lf", &y2);
    
    printf("result: %f.
", dist(x1, y1, x2, y2));
    
    return 0;
}

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14788856.html