Wrong C code - help!
I want to ask someone who got AC what's wrong here:
#include<stdio.h>
#include<math.h>
#define pi acos(-1)
typedef struct {double x; double y;} point;
FILE *f;
int i,i1,i2,i3,n;
double a,b,c,r,res;
point p[100];
double sqr(double x)
{ return x*x;
}
double len(point p1, point p2)
{ return sqrt(sqr(p2.x-p1.x)+sqr(p2.y-p1.y));
}
double findArc(double b, double a, double c, double r)
/* Inversed because of the sides of triangle */
{ double gama;
gama=acos((b*b+a*a-c*c)/(2*b*a));
return (pi-gama)*r;
}
int main(void)
{ f=stdin;
/* f=fopen("ROPE.IN1","r"); */
fscanf(f,"%d %lf",&n,&r);
for (i=0;i<n;i++)
fscanf(f,"%lf %lf",&p[i].x,&p[i].y);
fclose(f);
res=0;
for (i=0;i<n;i++)
{ i1=i; i2=i+1; i3=i+2;
if (i==n-2) i3=0; else if (i==n-1) {i2=0; i3=1;}
a=len(p[i1],p[i2]); b=len(p[i2],p[i3]);
c=len(p[i3],p[i1]);
/*
printf("\n-----\n@ %d %d %d",i1,i2,i3);
printf("\n& %.2lf %.2lf %.2lf",a,b,c);
printf("\n# %.2lf %.2lf",a,findArc(a,b,c,r));
*/
res+=a+findArc(a,b,c,r);
}
printf("%0.2lf",res);
return 0;
}