给定n个点的坐标,求多边形面积:点击打开链接
#include <stdio.h>
#include <string.h>
struct Point {
int x, y;
};
int
main() {
struct Point p[105];
int n, i;
double area;
while (scanf("%d", &n) == 1 && n) {
memset(p, 0, sizeof(p));
for (i = 0; i < n; ++ i)
scanf("%d%d", &p[i].x, &p[i].y);
area = 0.0;
for (i = 1; i < n - 1; ++ i)
area += p[0].x*p[i+1].y + p[0].y*p[i].x + p[i+1].x*p[i].y - p[0].x*p[i].y -p[0].y*p[i+1].x -p[i+1].y*p[i].x;
area /= 2;
printf("%.1lf\n", -area);
}
}