[C Language], and the area of a given right-angled triangle hypotenuse

 

Skipped school HugeGun_

Time limit: 1000ms Memory Limit: 65536kb

Title Description

HugeGun sister liked skipped school. Unfortunately, this time she was found.

Teacher asked her to clean the classroom. When she suddenly found that the broom against the wall, since the light from directly above, with the broom in the shadow of the walls and the ground constitute a right triangle.

She would like to know, for a right-angled triangle, the hypotenuse of a given area and the edge length of the triangle, how to calculate the side length of the right-angled edge.

Wise course you would help her.

Entry

A first line integer n- n-represents the number of data sets

Next, n- n-lines of two integers L , S L, S respectively represent area size and length of the hypotenuse

Export

Output n- n-row

First i i Behavior i i-answer sets of data:

If you can not find the right-angle side length condition is satisfied, output hhhg.

Otherwise the outputs of the two two decimal places A , B A, B represents a right-angle side length, which needs to satisfy A <= B A <B =

SAMPLE INPUT

3
5 6
7 8
1 2

Sample Output

3.00 4.00
2.44 6.56
hhhg

data range

1l106

0Sl2

[Solution] My question

It is provided on both sides of a triangle a, b, L hypotenuse;

S=1/2*a*b;

l' 2 = of a 2 + . b 2 ;

Solving equations have to answer.

#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
    double a,b,l,s;
    double gen1,gen2;
    int n;
    scanf("%d",&n);
    while(n--){
        scanf("%lf%lf",&l,&s);
        if(l*l<4*s) {
            printf("hhhg\n");
            continue;
        }
        gen1=sqrt(l*l-4*s);
        gen2=sqrt(l*l+4*s);
        a=(gen2+gen1)/2;
        b=(gen2-gen1)/2;
        printf("%.2lf %.2lf\n",b,a); 
    }
    return 0;
}

Thank you for visiting!

 

Guess you like

Origin www.cnblogs.com/life-blog-of-Dolly/p/11965750.html