c语言 平面n个点坐标,计算各点间距离之和(struct coordinative)

2025-01-02 04:25:50
推荐回答(2个)
回答1:

#include "stdio.h"
#include "math.h"
struct cpprdinative{
float x;
float y;
}point[10];
void main()
{
int n = 0;
printf("n=");scanf("%d", &n);
for(int i = 0;i < n; i ++)
{
scanf("%f,%f", &point[i].x, &point[i].y);
}
float Distance =0;
for(int i = 0; i < n; i ++)
{
for(int j = i+1; j < n;j ++)
{
Distance += sqrt((point[i].x-point[j].x)*(point[i].x-point[j].x)+ (point[i].y-point[j].y)*(point[i].y-point[j].y));
}
}
printf("Distance = %f", Distance);
}
// 输入
n=10
63,22
56,25
50,30
42,37
53,45
60,55
70,55
76,49
80,40
72,28
// 输出
Distance = 1029.568237

回答2:

是两点间的距离还是啥