Analyzing triangular Problem 3-5 (15 minutes)

The coordinate (x 1, y 1) given any three points on a plane, (x 2, y 2), (x 3, y 3 ), whether they could form a triangle.

Input formats:

Input given order number in the range of six [-100,100] in a row, i.e., three points the coordinates x 1, y 1, x 2, y 2, x 3, y 3.

Output formats:

If the three points form a triangle not, then output "Impossible" in a row; if possible, the output of the triangular perimeter and area in a row, the format of "L = the perimeter, A = area", is output to the decimal point after two.

Sample Input 1:

4 5 6 9 7 8

 

Output Sample 1:

L = 10.13, A = 3.00

 

Sample Input 2:

4 6 8 12 12 18

 

Output Sample 2:

Impossible

 answer:

#include<stdio.h>
#include<math.h>
int main(){
    double x1,y1,x2,y2,x3,y3,x,y,z;
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    x=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    y=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
    z=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
    if(x+y<=z||x+z<=y||y+z<=x){
        printf("Impossible");
    }else{
        double L,A,p;
        p=(x+y+z)/2;
        A=sqrt(p*(p-x)*(p-y)*(p-z));
        L=x+y+z;
        printf("L = %.2lf, A = %.2lf",L,A);
    }
    return 0;
}

 

Published 98 original articles · won praise 2 · Views 3737

Guess you like

Origin blog.csdn.net/qq_30377869/article/details/104753963