描述
平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少,精确到小数点后两位。
输入
输入仅一行,包括6个浮点数,分别对应x1, y1, x2, y2, x3, y3。
输出
输出也是一行,输出三角形的面积,精确到小数点后两位。
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
double x1,y1,x2,y2,x3,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
double a,b,c,d;
a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
d = (a+b+c)/2;
cout<<fixed<<setprecision(2)<<(double)sqrt(d*(d-a)*(d-b)*(d-c))<<endl;
return 0;
}