... #define SQUARE(a) ((a) * (a)) struct Point { int x; int y; }; ... int main() { ... const int numOfPoints = 4; Point points[numOfPoints]; ... double p = 0; for (int i = 0; i < numOfPoints - 1; i++) p += sqrt(SQUARE(points[i + 1].x - points[i].x)) + SQUARE(points[i + 1].y - points[i].y));
#define SQUARE(a) ((a) * (a))
struct Point
{
int x;
int y;
};
...
int main()
{
...
const int numOfPoints = 4;
Point points[numOfPoints];
...
double p = 0;
for (int i = 0; i < numOfPoints - 1; i++)
p += sqrt(SQUARE(points[i + 1].x - points[i].x)) + SQUARE(points[i + 1].y - points[i].y));
p += sqrt(SQUARE(points[numOfPoints - 1].x - points[0].x)) + SQUARE(points[numOfPoints - 1].y - points[0].y));
}