Note that there are some explanatory texts on larger screens.

plurals
  1. POTravelling Salesman C Program Error
    text
    copied!<p>Am writing a programme to solve TSP for n towns(towns and shortest route to cover them all). The approach is to ask the user for the coordinates of towns and then the programme should calculate the distance using the equation for distance between two points on the plain: d=((x2-x1)^2+(y2-y1)^2)^1/2;</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; void check(int); int distance(int, int, int); int main(int argc, char *argv[]) { int n; int i; //number of towns int coord[12][3]; int dist[12][12]; printf("how many towns?\n");//should be more than 1 and no more than 12 to be handled by the compiler scanf("%d", &amp;n); check(n); printf("for the plain 10x10 give town coordinates\n\n");//e.g. 1(0,4), 2(3,7) for(i=0; i&lt;n; i++) { coord[i][0]=i+1;//town number printf("town %d\n", i+1); printf("x=\n"); scanf("%d", &amp;coord[i][1]);//first coordinate printf("y=\n"); scanf("%d", &amp;coord[i][2]);//second coordinate printf("\n"); } distance(n, coord, dist); system("PAUSE"); return 0; } void check(int n) { if(n&lt;=1) printf("wrong number; start over\n"); return; } int distance(int n, int coord[][], int dist[][]) { int i; int j; for(i=0; i&lt;n; i++) { for(j=0; j&lt;n; j++) { dist[i][j]=sqrt(pow((coord[i][1]-coord[j][1]), 2)- pow((coord[i][2]-coord[j][2]), 2)); printf("%d\n", dist[i][j]; } } } </code></pre> <p>The program is only partially done and I wanted to test whether the programme can print the distance between each town. However I get this error: "passing arg 2 'distance' makes integer from pointer without cast" I am aware that dist should return flow, but I was testing different formats as well changing number of variables in 'distance' function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload