Let me know if there is any bug
/*using centroid of plane */
struct point
{
int x;
int y;
};
typedef struct point Point;
int main()
{
int n,i;
int d,dis;
float sum_x=0,sum_y=0;
Point centroid,final;
//clrcsr();
printf("how many points? ");
scanf("%d",&n);
Point p[100];
printf("enter X and Y cordinates of %d points\n",n);
for(i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
for(i=0;i<n;i++)
{
sum_x=sum_x+p[i].x;
sum_y=sum_y+p[i].y;
}
centroid.x=(int)sum_x/n;
centroid.y=(int)sum_y/n;
for(i=0;i<n;i++)
{
dis=distance(centroid,p[i]);
if(dis<d)
{
d=dis;
final.x=p[i].x;
final.y=p[i].y;
}
}
printf("\n The point is (%3d ,%3d)",final.x,final.y);
getch();
return 0;
}
int distance(Point A,Point B)
{
int x,y;
x=(A.x-B.x)*(A.x-B.x);
y=(A.y-B.y)*(A.y-B.y);
return sqrt(x+y);
}
On Mon, Apr 30, 2012 at 4:34 PM, kosgi santosh <[email protected]>wrote:
> how can we find centriod of n points in a plane?
>
>
>
>
>
> Regards,
> Santosh K.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.