习题3-5 三角形判断

给定平面上任意三个点的坐标(、(、(,检验它们能否构成三角形。

输入格式:

输入在一行中顺序给出六个[范围内的数字,即三个点的坐标x1​​、y1​​、x2​​、y2​​、x3​​、y3​​。

输出格式:

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

输入样例1:

4 5 6 9 7 8

输出样例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,p;
     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;
        p=L*0.5;
         A=sqrt(p*(p-a)*(p-c)*(p-b));
         printf("L = %.2f, A = %.2f\n",L,A ); 
     }
    return 0;
}
 

 

已知三角形三边a,b,c,则

(海伦公式)(p=(a+b+c)/2)

S=sqrt[p(p-a)(p-b)(p-c)]

 

posted @ 2021-03-19 13:41  醉月8848  阅读(115)  评论(0)    收藏  举报