Stil about simulated programming,,, Here is the code I have. Firstly, it must generate a path using number 1 to 6 to represent the city. Then it will calculate the distance (using the coordinate). But, in fact, the output of the distance doesn't appropriate with the coordinate of the randomed path. The output of the distance always 129.08, which is the distance city 1 to city 6. every time the code is deployed, it always prints 6 cities, randomed, but the distance isn't change. please help me.
thank you!!
Code:
int NC=6; // the amount of cities
float X[6]={10.00,30.00,15.00,25.00,10.00,30.00}; // the coordinate of city
float Y[6]={0.00,0.00,20.00,20.00,30.00,30.00};//the coordinate of city
double panjang3=0;
void pjgJalur()
{
double panjang2=0;
double panjang4=0;
int i;
//printf("%2.2f",X[2]);
for (i=0;i<NC-1;i++)
{
panjang2=sqrt(pow((X[i+1]-X[i]),2)+pow((Y[i+1]-Y[i]),2));
panjang3=panjang3+panjang2;
}
panjang4=sqrt(pow((X[5]-X[0]),2)+pow((Y[5]-Y[0]),2));
panjang3=panjang3+panjang4;
}
void random1()
{
int b;
randomize();
ulang2:
int a=random (6);
a=a+1;
if (a==6)
{
goto ulang2;
}
else{
printf("R1: %d\n",a);
ulang:
b=random (6);
b=b+1;
// printf("R2a: %d\n",b);
if (a<b)
{
printf("R2: %d\n",b);
}
else{
goto ulang;
}
}
}
void random2()
{
randomize();
for (int a=0;a<10;a++)
{
float x=random (99);
x=x/100;
printf("Random number in the 0,1-0,99 range: %2.2f\n",x);}
}
int x[6]={0,0,0,0,0,0};
void random3()
{
int y,a;
int b=0;
int c=0;
randomize();
y= random (6);
y=y+1;
printf("Kota 1: %d\n",y);
x[0]=y;
for (a=1;a<6;a++)
{
ulang:
c=0;b=0;
x[a]= random (7);
x[a]=x[a]+1;
cek:
if(a!=b)
{
if (x[a]==x[b])
{
goto ulang;
}
else
{
if(c==6){
goto lanjut;}
else {b++;
c++;goto cek;}
}
}
if(a==b) {b++;c++;goto cek;}
lanjut:
printf("Kota %d: %d\n",a+1,x[a]);
}
}
void T0()
{
float LMax=0;
}
void JalurBaru()
{
int a,b,x[6];
int depan[6],tengah[6],belakang[6];
random1();
}
void main()
{
random3();
JalurBaru();
pjgJalur();
printf("%2.2f",panjang3);
}
Comment