帮忙看看……错误
#include <math.h>#include <stdio.h>
struct point
{
double x;
double y;
};
point gravity(point *p,int n);
int main(int argc, char *argv[])
{
int n;
point life,back;
struct point *ps;
ps=&life;
printf("请输入x,y");
scanf("%f %f",ps->x,ps->y);
printf("请输入点数n");
scanf("%d",n);
back=gravity(ps,n);
printf ("坐标为(%d,%d)",back.x,back.y);
return 0;
}
point gravity(point *p,int n)
{
double area = 0;
point center;
center.x = 0;
center.y = 0;
int i;
for(i = 0; i < n-1; i++)
{
area += (p[i].x*p[i+1].y - p[i+1].x*p[i].y)/2;
center.x += (p[i].x*p[i+1].y - p[i+1].x*p[i].y) * (p[i].x + p[i+1].x);
center.y += (p[i].x*p[i+1].y - p[i+1].x*p[i].y) * (p[i].y + p[i+1].y);
}
area += (p[n-1].x*p[0].y - p[0].x*p[n-1].y)/2;
center.x += (p[n-1].x*p[0].y - p[0].x*p[n-1].y) * (p[n-1].x + p[0].x);
center.y += (p[n-1].x*p[0].y - p[0].x*p[n-1].y) * (p[n-1].y + p[0].y);
center.x /= 6*area;
center.y /= 6*area;
return center;
}