C语言计算平面两点距离:自定义函数Distance
#include <stdio.h> #include <math.h>
float Distance(float x1, float y1, float x2, float y2) { float distance; distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); return distance; }
int main() { float x1, y1, x2, y2; printf("Enter the coordinates of point 1 (x y): "); scanf("%f %f", &x1, &y1); printf("Enter the coordinates of point 2 (x y): "); scanf("%f %f", &x2, &y2); float distance = Distance(x1, y1, x2, y2); printf("The distance between the two points is: %.2f\n", distance); return 0; }
原文地址: https://www.cveoy.top/t/topic/pnGZ 著作权归作者所有。请勿转载和采集!