这个程序哪的错呢,实在找不出(目的可求N组三角形面积)
请高手指点,谢谢啦!代码如下:
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
double a[10000],b[10000],c[10000]; //三角形三边长
int x1[10000],y1[10000],x2[10000],y2[10000],x3[10000],y3[10000]; //三角形三点坐标
double p,s; //s 三角形面积
double godistance(int x1,int y1,int x2,int y2);
int n;
//cin>>n;
// cout<<"请分别输入三定点的坐标:";
for (int i=0;i<10000;i++)
{
cin>>x1[i]>>y1[i]>>x2[i]>>y2[i]>>x3[i]>>y3[i];
n++;
if(((x1[i]==x2[i])&&(y1[i]==y2[i]))||((x1[i]==x3[i])&&(y1[i]==y3[i]))||((x3[i]==x2[i])&&(y3[i]==y2[i]))) break;
//x1[i]==0)&&(x2[i]==0)&&(x3[i]==0)&&(y1[i]==0)&&(y2[i]==0)&&(y3[i]==0
}
for(i=0;i<n-1;i++)
{
a[i]=godistance(x1[i],y1[i],x2[i],y2[i]);
b[i]=godistance(x2[i],y2[i],x3[i],y3[i]);
c[i]=godistance(x1[i],y1[i],x3[i],y3[i]);
p=(a[i]+b[i]+c[i])/2;
s=sqrt(p*(p-a[i])*(p-b[i])*(p-c[i]));
printf("%0.1f\n",s);
}
return 0;
}
double godistance(int x1,int y1,int x2,int y2)
{
double d;
d=sqrt((x1-x2)*(x1-x2)-(y1-y2)*(y1-y2));
return d;
}