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 email@example.com. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Number of possible pairs of Hypotenuse and Area to form right angled triangle
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Find the hypotenuse of a right angled triangle with given two sides
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Area of a largest square fit in a right angle triangle
- Area of Circumcircle of a Right Angled Triangle
- Area of Incircle of a Right Angled Triangle
- Find the height of a right-angled triangle whose area is X times its base
- Check if a right-angled triangle can be formed by the given coordinates
- Minimum height of a triangle with given base and area
- Area of triangle formed by the axes of co-ordinates and a given straight line
- Check whether right angled triangle is valid or not for large sides
- Check if a right-angled triangle can be formed by moving any one of the coordinates
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Find area of triangle if two vectors of two adjacent sides are given
- Area of a Triangle from the given lengths of medians
- Count of Right-Angled Triangle formed from given N points whose base or perpendicular are parallel to X or Y axis
- Program to calculate area and perimeter of equilateral triangle
- Find the altitude and area of an isosceles triangle
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle
Improved By : vt_m