C语言,求三角形面积:从键盘输入三个顶点坐标(x1,y1)(x2,y2)(x3,y3)假设可能构成?

如题所述

第1个回答  2021-03-28
根据坐标,可以算出三个边长。
然后再。。。
第2个回答  2021-03-28

#include <stdio.h>

#include <math.h>

double dist(double x1,double y1,double x2,double y2)

{return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

}

int main()

{ double a,b,c,p,s,x[3],y[3];

  int i;

  for(i=0;i<3;i++)

    scanf("%lf%lf",&x[i],&y[i]);

  a=dist(x[0],y[0],x[1],y[1]);  

  b=dist(x[0],y[0],x[2],y[2]);  

  c=dist(x[1],y[1],x[2],y[2]);

  p=(a+b+c)/2;  

  s=sqrt(p*(p-a)*(p-b)*(p-c));

  printf("s=%f\n",s);

  return 0;

}

相似回答