C语言计算平面两点间距离:结构体和函数实现
#include <stdio.h>\n#include <math.h>\n\nstruct POINTER {\n float x; \n float y; \n};\n\nfloat Distance(struct POINTER p1, struct POINTER p2) {\n float distance; \n distance = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2)); \n return distance; \n}\n\nint main() {\n struct POINTER p1, p2; \n printf("Enter the coordinates of the first point:\n"); \n scanf("%f%f", &p1.x, &p1.y); \n printf("Enter the coordinates of the second point:\n"); \n scanf("%f%f", &p2.x, &p2.y); \n \n float distance = Distance(p1, p2); \n printf("The distance between the two points is: %.2f\n", distance); \n \n return 0; \n}
原文地址: https://www.cveoy.top/t/topic/pnGO 著作权归作者所有。请勿转载和采集!