复件 复件 points.c
来自「凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形」· C语言 代码 · 共 22 行
C
22 行
#include <stdio.h>
#define MAX_LINE_N 15
int main()
{
double point[MAX_LINE_N+1][2]={0,0};
int i=0, j=0;
double area=0.0;
//get x and y from stdin
while(scanf("%lf%lf", &point[i][0], &point[i][1]) != EOF)
i++;
//copy the first point to the position behind the last point
point[i][0] = point[0][0];
point[i][1] = point[0][1];
//compute the area of polygon by dividing it into several trapezoids
for (j=0; j<i; j++)
area += (point[j][1] - point[j+1][1]) * (point[j][0] + point[j+1][0]) / 2;
//print the area retaining two decimal
printf("%.2f", area);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?