17:计算三角形面积

OpenJudge-1.3编程基础之算术表达式与顺序执行-17:计算三角形面积
总Time Limit: 1000ms     Memory Limit: 65536kB

Description

平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少。

Input

输入仅一行,包括6个单精度浮点数,分别对应x1, y1, x2, y2, x3, y3。

Output

输出也是一行,输出三角形的面积,精确到小数点后两位。

Sample Input

0 0 4 0 0 3

Sample Output

6.00

Hint

海伦公式

C++ Code

#include <bits/stdc++.h>
using namespace std;
int main()
{
      float a,b,m,n,x,y;
      scanf("%f%f",&a,&b);
      scanf("%f%f",&m,&n);
      scanf("%f%f",&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;
}
posted @ 2021-01-29 20:27  Programmer-sun  阅读(527)  评论(0编辑  收藏  举报