Title description
It is known that the coordinates of the three vertices of the triangle in the Cartesian coordinate system are:
(2.3, 2.5)
(6.4, 3.1)
(5.1, 7.2)
Find the area of the triangle.
The output is
required to be accurate to 3 decimal places. If it is less than 3 digits, zero should be added.
Helen's formula:
Code:
#include <iostream>
using namespace std;
double len(double x1,double y1,double x2,double y2){
//两点距离
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
double a,b,c,p,s;
a = len(2.3,2.5,6.4,3.1); //三条边长 a b c
b = len(2.3,2.5,5.1,7.2);
c = len(6.4,3.1,5.1,7.2);
p = (a+b+c)/2; //半周长
s = sqrt(p*(p-a)*(p-b)*(p-c)); //面积公式
printf("%.3f",s); //保留三位
return 0;
}