Your SlideShare is downloading.
×

- 1. Does anyone can help me fix this problem using c langauge? Thank you so much! Solution /* calculate polygon perimeter */ double perimeter(double *vertices, int size) { int idx, jdx; double p1[2], p2[2], pfirst[2], plast[2]; double perimeter; perimeter = 0.0; /* 1st vertex of the polygon */ pfirst[x] = vertices[0]; pfirst[y] = vertices[1]; /* last vertex of polygon */ plast[x] = vertices[size-2]; plast[y] = vertices[size-1]; /* calculate perimeter minus last side */ for(idx = 0; idx <= size-3; idx += 2) { for(jdx = 0; jdx < 4; ++jdx) { p1[x] = vertices[idx]; p1[y] = vertices[idx+1]; p2[x] = vertices[idx+2]; p2[y] = vertices[idx+3]; } perimeter += side(p1, p2); } /* add last side */ perimeter += side(plast, pfirst); return perimeter; }
- 2. vertices means array of vertices stored