看看我这代码哪里错了
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct guandao
{
float x[100];
float y[100];
} g;
main()
{
FILE *in=fopen( "in.txt ", "r ") ;
FILE *out=fopen( "out.txt ", "w ");
int i,j;
float temp;
for(i=0;i <100;i++)
{
fscanf(in, "%f %f ",&g.x[i],&g.y[i]);
}
for(i=0;i <100;i++)
for(j=0;j <=100-i;j++)
{
if(g.y[i]> g.y[i+1])
{
temp=g.x[i];
g.y[i]=g.y[i+1];
g.y[i+1]=temp;
}
}
if(j/2==0)
fprintf(out, "%f\n ",(g.y[j]+g.y[1])/2);
else
fprintf(out, "%f\n ",(g.y[j/2+1]));
fclose(in);
fclose(out);
return 0;
}
平行与X轴修建一条主管线,使其到个接口的距离最短(接口用平行与Y的管道链接主管线)
我这个输入坐标时不按大小顺序输入就出错误的结果,帮帮芒
[解决办法]
temp=g.x[i]; ---------> temp = g.y[i];
g.y[i]=g.y[i+1];
g.y[i+1]=temp;