可以帮我该一下这个代码吗?求任意多边形面积.#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/07/03 12:11:57
![可以帮我该一下这个代码吗?求任意多边形面积.#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 (](/uploads/image/z/2089440-0-0.jpg?t=%E5%8F%AF%E4%BB%A5%E5%B8%AE%E6%88%91%E8%AF%A5%E4%B8%80%E4%B8%8B%E8%BF%99%E4%B8%AA%E4%BB%A3%E7%A0%81%E5%90%97%3F%E6%B1%82%E4%BB%BB%E6%84%8F%E5%A4%9A%E8%BE%B9%E5%BD%A2%E9%9D%A2%E7%A7%AF.%23include+%23includeusing+namespace+std%3Bint+N%3Bstruct+point%7Bdouble+x%2Cy%3B%7D%3Btypedef+point+polygon%5BN%5D%3Bdouble+polygon_area%28polygon+p%2Cint+n%29%7Bdouble+area%3D0.0%3Bint+i%3Bfor+%28i%3D1%3B+i%3En%29%7Bif+%28n%3D%3D0%29break%3Bfor+%28)
可以帮我该一下这个代码吗?求任意多边形面积.#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