c语言编写程序定义一个结构体类型POINTER其成员用于记录平面中几何点的坐标。请编写程序在main函数中调用自定义函数Distance计算平面中两个点之间的距离。函数原型为floatDistance POINTER p1POINTER p2不用结构体
#include <stdio.h> #include <math.h>
struct POINTER { float x; float y; };
float Distance(struct POINTER p1, struct POINTER p2) { float distance; distance = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2)); return distance; }
int main() { struct POINTER p1, p2; printf("Enter the coordinates of point 1 (x y): "); scanf("%f %f", &p1.x, &p1.y); printf("Enter the coordinates of point 2 (x y): "); scanf("%f %f", &p2.x, &p2.y); float distance = Distance(p1, p2); printf("The distance between the two points is: %.2f\n", distance); return 0;
原文地址: https://www.cveoy.top/t/topic/hECM 著作权归作者所有。请勿转载和采集!