Successfully reported this slideshow.
Your SlideShare is downloading. ×

Does anyone can help me fix this problem using c langauge- Thank you s.docx

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 2 Ad

Does anyone can help me fix this problem using c langauge- Thank you s.docx

Download to read offline

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;
}
vertices means array of vertices stored
.

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;
}
vertices means array of vertices stored
.

Advertisement
Advertisement

More Related Content

More from wviola (20)

Recently uploaded (20)

Advertisement

Does anyone can help me fix this problem using c langauge- Thank you s.docx

  1. 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. 2. vertices means array of vertices stored

×