1034:计算三角形面积
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 20586 通过数: 6171
【题目描述】
平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),
那么请问这个三角形的面积是多少,精确到小数点后两位。
【输入】
输入仅一行,包括6个单精度浮点数,分别对应x1, y1, x2, y2, x3, y3。
【输出】
输出也是一行,输出三角形的面积,精确到小数点后两位。
【输入样例】
0 0 4 0 0 3
【输出样例】
6.00
【来源】
No
代码
#include <cstdio>
#include <cmath>
using namespace std;
double bianchang (double a1,double a2,double b1,double b2)
{
return sqrt((a1-b1)*(a1-b1)+(a2-b2)*(a2-b2));
}
int main ()
{
double x1, y1, x2, y2, x3, y3;
scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
double A=bianchang(x1,y1,x2,y2);
double B=bianchang(x2,y2,x3,y3);
double C=bianchang(x3,y3,x1,y1);
double q=(A+B+C)/2;
double S=sqrt(q*(q-A)*(q-B)*(q-C));
printf("%.2lf",S);
return 0;
}