预计阅读时间:5分钟
原题
描述
平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少。
输入
输入仅一行,包括6个单精度浮点数,分别对应x1, y1, x2, y2, x3, y3。
输出
输出也是一行,输出三角形的面积,精确到小数点后两位。
样例输入
0 0 4 0 0 3
样例输出
6.00
提示
海伦公式
代码
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float a,b,m,n,x,y;
cin>>a>>b;
cin>>m>>n;
cin>>x>>y;
double s,i,j;
s=sqrt((m-x)*(m-x)+(n-y)*(n-y));
i=sqrt((m-a)*(m-a)+(n-b)*(n-b));
j=sqrt((a-x)*(a-x)+(b-y)*(b-y));
double p;
p=(s+i+j)/2;
double S;
S=sqrt(p*(p-s)*(p-i)*(p-j));
printf("%.2lf",S);
return 0;
}
希望本博客对大家有所帮助