当前位置:编程问答 > C/C++ >

NYOJ 67 三角形面积

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double segment(double a,double b);
double area(double a,double b,double c);
int main()
{
 int j,i=0;
 double h[10000];
    double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
        while((x1+x2+x3+y1+y2+y3)!=0)
   {
         double a=segment((x1-x2),(y1-y2));
         double b=segment((x2-x3),(y2-y3));
         double c=segment((x3-x1),(y3-y1));
            h[i]=area(a,b,c);
   i++;
            cin>>x1>>y1>>x2>>y2>>x3>>y3;
   }
     for(j=0;j<i;j++)
  {
   cout<<setiosflags(ios::fixed)<<setprecision(1);
   cout<<h[j]<<endl;
  }
 return 0;
}
double segment(double a,double b)
{
 double k=sqrt(a*a+b*b);
 return k;
}
double area(double a,double b,double c)
{
 double s=sqrt((a+b+c)*(a+b-c)*(a+c-b)*(b+c-a))/4;
 return s;
}
        
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,