/* Perimetro di un poligono */

#include <stdio.h>
#include <math.h>

typedef struct { 
    float x; 
    float y;
} punto;

#define N 5

typedef punto poligono[N];

int main(){
    poligono p = { {0, 0}, {0, 1}, {1, 1}, {2, 2}, {2,0}  };
    float peri = 0;
    int i;
    for(i=0; i<N-1; i++) {
        float dx = p[i].x-p[i+1].x;
        float dy = p[i].y-p[i+1].y;
        peri += sqrt ( dx*dx + dy*dy );
        printf("i=%d : dx=%f, dy=%f\n", i, dx, dy);
    }
    peri += sqrt ( 
            (p[0].x-p[N-1].x)*(p[0].x-p[N-1].x) +
            (p[0].y-p[N-1].y)*(p[0].y-p[N-1].y) );
    printf("Perimetro = %f\n", peri);
    return 0;
}
