Given area and hypotenuse, the aim is to print all sides if right triangle can exist, else print -1. We need to print all sides in ascending order.
Input : 6 5 Output : 3 4 5 Input : 10 6 Output : -1
We have discussed a solution of this problem in below post.
Find all sides of a right angled triangle from given hypotenuse and area | Set 1
In this post, a new solution with below logic is discussed.
Let the two unknown sides be a and b
Area : A = 0.5 * a * b
Hypotenuse Square : H^2 = a^2 + b^2
Substituting b, we get H2 = a2 + (4 * A2)/a2
On re-arranging, we get the equation a4 – (H2)(a2) + 4*(A2)
The discriminant D of this equation would be D = H4 – 16*(A2)
If D = 0, then roots are given by the linear equation formula, roots = (-b +- sqrt(D) )/2*a
these roots would be equal to the square of the sides, finding the square roots would give us the sides.
3 4 5
This article is contributed by Harshit Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Number of possible pairs of Hypotenuse and Area to form right angled triangle
- Find the hypotenuse of a right angled triangle with given two sides
- Area of Reuleaux Triangle
- Area of Incircle of a Right Angled Triangle
- Area of Circumcircle of a Right Angled Triangle
- Area of a triangle inside a parallelogram
- Find the coordinates of a triangle whose Area = (S / 2)
- Program to find area of a triangle
- Area of a largest square fit in a right angle triangle
- Area of circle which is inscribed in equilateral triangle
- Area of largest triangle that can be inscribed within a rectangle
- Area of the Largest Triangle inscribed in a Hexagon
- Maximum area of triangle having different vertex colors
- Find the altitude and area of an isosceles triangle
Improved By : vt_m