习题3-5 三角形判断 (15 point(s))

习题3-5 三角形判断 (15 point(s))

给定平面上任意三个点的坐标(x​1​​,y​1​​)、(x​2​​,y​2​​)、(x​3​​,y​3​​),检验它们能否构成三角形。

输入格式:

输入在一行中顺序给出六个[−100,100]范围内的数字,即三个点的坐标x​1​​、y​1​​、x​2​​、y​2​​、x​3​​、y​3​​。

输出格式:

若这3个点不能构成三角形,则在一行中输出“Impossible”;若可以,则在一行中输出该三角形的周长和面积,格式为“L = 周长, A = 面积”,输出到小数点后2位。

输入样例1:

输出样例1:

L = 10.13, A = 3.00

输入样例2:

4 6 8 12 12 18

输出样例2:

Impossible
#include<stdio.h>
#include<math.h>
int main()
{
  double x1,y1,x2,y2,x3,y3;
  double a,b,c,L,A;
  scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
  a=sqrt(pow((x1-x2),2)+pow((y1-y2),2) );
  b=sqrt(pow((x1-x3),2)+pow((y1-y3),2) );
  c=sqrt(pow((x3-x2),2)+pow((y3-y2),2) );
  if((a+b)<=c||(a+c)<=b||(c+b)<=a){ 
    printf("Impossible");
    
  }else{
  L=a+b+c;
    A=sqrt(L*0.5*(L*0.5-a)*(L*0.5-b)*(L*0.5-c));
    printf("L = %.2f, A = %.2f",L,A);
    
  }
     
  return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42057358/article/details/84035201