I am using a for loop to calculate the distance between the vertices of a polygon

using

```
for (i=0; i<N, i++)
{
j= (i-1)
result = sqrt (sqr(X-X[j])+sqr(y-y[j]));
}
return result;
```

This work fine however it doesn't and I cant calculate the distance between the last and first vertice e.g for N=4, calculates N0 to N1, N1 to N2, etc, but doesnt enclose the polygon and calculate N3 to N0

Is there any alteration to this code that will enable this, any help is much appreciated