这段代码,运行有问题,高手帮解
#include <stdio.h>#include <math.h>
struct xuanzhi
{
double x,y,c,r;
}
xz[4]={{3,10,1,1},{11.5,12.5,1,1},{3,3,1,1},{10,6,1,1};
main()
{
struct xuanzhi;
int i;
double d[4];
double x0=0.0,y0=0.0,min=0.0,TC=0.0,t=0.0,m=0.0,w=0.0,x1=0.0,y1=0.0,m1=0.0,m2=0.0,w2=0.0,t1=0.0,m3=0.0,w3=0.0;
for(i=0;i<4;i++)
{
m+=xz[i].c*xz[i].r*xz[i].x;
w+=xz[i].c*xz[i].r;
m1+=xz[i].c*xz[i].r*xz[i].y;
}
x0=m/w;
y0=m1/w;
for(i=0;i<4;i++)
{
d[i]=sqrt((xz[i].x-x0)*(xz[i].x-x0)+(xz[i].y-y0)*(xz[i].y-y0));
m3+=xz[i].c*xz[i].r*xz[i].x/d[i];
t1+=xz[i].c*xz[i].r*xz[i].y/d[i];
w3+=xz[i].c*xz[i].r/d[i];
}
x1=m3/w3;
y1=t1/w3;
do
{
x0=x1;
y0=y1;
for(i=0;i<4;i++)
{
d[i]=sqrt((xz[i].x-x0)*(xz[i].x-x0)+(xz[i].y-y0)*(xz[i].y-y0));
m2+=xz[i].c*xz[i].r*xz[i].x/d[i];
t+=xz[i].c*xz[i].r*xz[i].y/d[i];
w2+=xz[i].c*xz[i].w/d[i];
}
x1=m2/w2;
y1=t/w2;
m2=0.0;
t=0.0;
w2=0.0;
}while(fabs(x0-x1)-0.1>0&&fabs(y0-y1)-0.1>0);
printf("x0=%.2lf,y0=%.2lf\n",x0,y0);
for(i=0;i<4;i++)
{
d[i]=sqrt((xz[i].x-x0)*(xz[i].x-x0)+(xz[i].y-y0)*(xz[i].y-y0));
min=xz[i].c*xz[i].r*d[i];
TC+=min;
}
printf("x1=%.2lf\n y1=%.2lf\n", x1, y1);
getch();
}