c521

    平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少,精确到小数点后两位。
输入:
    输入仅一行,包括6个单精度浮点数,分别对应x1, y1, x2, y2, x3, y3。
输出:
    输出也是一行,输出三角形的面积,精确到小数点后两位。
样例输入:
    0 0 4 0 0 3
样例输出:
    6.00

#include<cstdio>
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
    double x1,y1,x2,y2,x3,y3;
    double l1,l2,l3,p,s;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    l1=sqrt(pow(y1-y2,2)+pow(x1-x2,2));
    l2=sqrt(pow(y1-y3,2)+pow(x1-x3,2));
    l3=sqrt(pow(y2-y3,2)+pow(x2-x3,2));
    p=(l1+l2+l3)/2;
    s=sqrt(p*(p-l1)*(p-l2)*(p-l3));
    cout<<fixed<<setprecision(2)<<s<<endl;
    return 0;
}
 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-12-19
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2021-12-26
  • 2021-12-18
  • 2022-02-08
  • 2022-12-23
  • 2021-11-23
  • 2021-12-10
  • 2022-12-23
相关资源
相似解决方案