给定三点坐标计算三角形面积
有两个考点:
考点一:两点间距离公式
考点二:海伦公式
海伦公式:
a b c 为三边长
p=(a+b+c)/2
S=√p(p-a)(p-b)(p-c)
//考点一:两点间距离公式
//考点二:海伦公式
#include<math.h>
#include<stdio.h>
int main()
{
double a1, a2, b1, b2, c1, c2;
double x1 = 0;
double x2 = 0;
double y1 = 0;
double y2 = 0;
double x3 = 0;
double y3 = 0;
scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
double a = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
double b = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
double c = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
double p = 0;
double s = 0;
p = (a + b + c) / 2;
s = sqrt(p * (p - a) * (p - b) * (p - c));
printf("%.2lf",s );
return 0;
}