Geometry Made Simple

Source: Internet
Author: User

Time limit: 2 Seconds Memory Limit: 65536 KB

Mathematics can is so and easy to have a computer. Consider the following example. You probably know this in a right-angled triangle, the length of the three sides A, B, C (where C is the longest side, Cal led the hypotenuse) satisfy the relation a*a+b*b=c*c. This is the called Pythagora ' s law.

Here we consider the problem of computing the length of the third side, if both are given.

Input

The input contains the descriptions of several triangles. Each description consists of a line containing three integers a, B and C, giving the lengths of the respective sides of a Right-angled triangle. Exactly one of the three numbers is equal to-1 (the ' unknown ' side), the others is positive (the ' given ' sides).

A description has a=b=c=0 terminates the input.


Output

For each triangle description in the input, first output the number of the triangle, as shown in the sample output. Then print "impossible." If there is no right-angled triangle, which has the ' given ' side lengths. Otherwise output the length of the ' unknown ' side in the format "s = L", where S is the name of the unknown side (a, B or c), and L are its length. L must is printed exact to three digits to the "right" of the decimal point.

Print a blank line after each test case.


Sample Input

3 4-1
-1 2 7
5-1 3
0 0 0


Sample Output

Triangle #1
c = 5.000

Triangle #2
A = 6.708

Triangle #3
Impossible.


At the beginning of the operation due to the lack of consideration to consider some of the circumstances of the two caused errors, such as one of the a,c,b in the case of 0, as well as the edge length should also consider the case of C less than a or B, but also to consider an edge length less than one case;

There is a '. ' Behind the impossible output. Remember, Triangle #1后面的一需要变化, C = 5.000 has a space between C and the equals sign, note that



#include <stdio.h>

#include <math.h>
int main ()
{
float A,b,c;
int i=1;
while (scanf ("%f%f%f", &a,&b,&c) && (a!=0| | b!=0| | c!=0))
{
printf ("Triangle #%d\n", i);
if (a==0| | b==0| | c==0)
{
i++;
printf ("impossible.\n\n");
Continue
}
if (a==-1)
{
i++;
if (c<=b| | c<0| | B&LT;0)
printf ("impossible.\n\n");
Else
printf ("A =%.3f\n\n", sqrt (c*c-b*b));
}


if (b==-1)
{
i++;
if (c<=a| | c<0| | A&LT;0)
printf ("impossible.\n\n");
Else
printf ("B =%.3f\n\n", sqrt (c*c-a*a));
}


if (c==-1)
{
i++;
if (a<0| | B&LT;0)
printf (". \ n");
Else
printf ("c =%.3f\n\n", sqrt (a*a+b*b));
}


}
return 0;
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Geometry Made Simple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.