定义二维空间中描述点的结构体类型包括x轴和y轴坐标值。输入两个点的坐标输出它们之间的距离输出格式:2f
#include <stdio.h> #include <math.h>
struct Point2D { double x; double y; };
int main() { struct Point2D p1, p2; double distance;
printf("Enter the coordinates of point 1:\n");
scanf("%lf %lf", &p1.x, &p1.y);
printf("Enter the coordinates of point 2:\n");
scanf("%lf %lf", &p2.x, &p2.y);
distance = sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
printf("The distance between the two points is: %.2f", distance);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/f3U1 著作权归作者所有。请勿转载和采集!