作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/18 00:27:02
c语言 平面n个点坐标,计算各点间距离之和(struct coordinative)
编程 输入平面上n(3
c语言 平面n个点坐标,计算各点间距离之和(struct coordinative)
#include "stdio.h"
#include "math.h"
struct cpprdinative{
\x05float x;
\x05float y;
}point[10];
void main()
{
\x05int n = 0;
\x05printf("n=");scanf("%d",&n);
\x05for(int i = 0;i < n; i ++)
\x05{
\x05\x05scanf("%f,%f",&point[i].x,&point[i].y);
\x05}
\x05float Distance =0;
\x05for(int i = 0; i < n; i ++)
\x05{
\x05\x05for(int j = i+1; j < n;j ++)
\x05\x05{
\x05\x05\x05Distance += 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));
\x05\x05}\x05
\x05}
\x05printf("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