⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 points.c

📁 凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积凸多边形面积
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -