/*code functions in static case but got to use dynamic array*/
#include
#include
#include
void main(int argc, char *argv[])
{
FILE *fp;
int i,j=0;
float n,x1,y1,x2,y2,cross,result,area=0,p[5][5];
clrscr();
fp=fopen(argv[1],"r");
if(fp==NULL)
{
printf("Cannot open file");
exit(0);
}
while(!feof(fp)) {
/* fread(&p[j][0],sizeof(p[j][0]),1,fp); */
fscanf(fp, "%f %f", &p[j][0],&p[j][1]);
printf("%f\n,%f\n",p[j][0],p[j][1]);
j++;
}
j=j-1;
for( i = 1; i+1<=j; i++)
{
x1 = p[i][0] - p[0][0];
y1 = p[i][1] - p[0][1];
x2 = p[i+1][0] - p[0][0];
y2 = p[i+1][1] - p[0][1];
printf("x1 is %f\ny1 is %f\nx2 is %f\ny2 is %f\n",x1,y1,x2,y2);
cross = x1*y2 - x2*y1;
printf("cross is %f\n",cross);
area += cross;
}
result = fabs(area/2.0);
printf("The area is %f",result);
}
2007-12-10
23:21:53
·
4 answers
·
asked by
Ankit
1
in
Computers & Internet
➔ Programming & Design