可以帮我该一下这个代码吗?求任意多边形面积.#include #includeusing namespace std;int N;struct point{double x,y;};typedef point polygon[N];double polygon_area(polygon p,int n){double area=0.0;int i;for (i=1; i>n){if (n==0)break;for (
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/20 00:41:12
可以帮我该一下这个代码吗?求任意多边形面积.#include #includeusing namespace std;int N;struct point{double x,y;};typedef point polygon[N];double polygon_area(polygon p,int n){double area=0.0;int i;for (i=1; i>n){if (n==0)break;for (
可以帮我该一下这个代码吗?求任意多边形面积.
#include
#include
using namespace std;
int N;
struct point
{
double x,y;
};
typedef point polygon[N];
double polygon_area(polygon p,int n)
{
double area=0.0;
int i;
for (i=1; i>n)
{
if (n==0)break;
for (int i=0;i>p[i].x>>p[i].y;
}
cout.precision(1);
cout
可以帮我该一下这个代码吗?求任意多边形面积.#include #includeusing namespace std;int N;struct point{double x,y;};typedef point polygon[N];double polygon_area(polygon p,int n){double area=0.0;int i;for (i=1; i>n){if (n==0)break;for (
这样改吧.这个程序可以输入些提示文字优化一下,比如提示输入边数、输入坐标要按顺序
#include
#include
using namespace std;
typedef struct
{
double x,y;
}polygon;
double polygon_area(polygon *p,int n)
{
double area=0.0;
int i;
for (i=1; ix*(p+i%n)->y-(p+i%n)->x*(p+i-1)->y;
return fabs(area)/2;
}
int main()
{
polygon *p;
int n,i;
while (cin>>n)
{
if(n==0) break;
p=new polygon[n]; //指针比数组好用,这里n是输进去的,要用动态分配内存
for (i=0;i>(p+i)->x>>(p+i)->y;
}
cout.precision(1);
cout