Given one side of right angle triangle, check if there exists a right angle triangle possible with any other two sides of the triangle. If possible print length of the other two sides and all the angles of the triangle.
Input : a = 12
Output : Sides are a = 12, b = 35, c = 37
Angles are A = 18.9246, B = 71.0754, C = 90
Explanation: a = 12, b = 35 and c = 37 form right
angle triangle because
12*12 + 35*35 = 37*37
Input : a = 6
Output : Sides are a = 6, b = 8, c = 10
Angles are A = 36.8699, B = 53.1301, C = 90
Approach to check if triangle exists and finding Sides:
To solve this problem we first observe the Pythagoras equation. If a and b are the lengths of the legs of a right triangle and c is the length of the hypotenuse, then the sum of the squares of the lengths of the legs is equal to the square of the length of the hypotenuse.
This relationship is represented by the formula:
a*a + b*b = c*c
Case 1: a is an odd number: Given a, find b and c
c2 - b2 = a2 OR c = (a2 + 1)/2; b = (a2 - 1)/2;
Above solution works only for case when a is odd, because a2 + 1 is divisible by 2 only for odd a.
Case 2 : a is an even number: When c-b is 2 & c+b is (a2)/2
c-b = 2 & c+b = (a2)/2 Hence, c = (a2)/4 + 1; b = (a2)/4 - 1;
This works when a is even.
Approach to find Angles:
First find all sides of triangle. Then Applied “SSS” rule that’s means law of cosine:
Below is the implementation of the above approach:
Side b = 35, Side c = 37 Angles are A = 18.9246, B = 71.0754, C = 90
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find other two sides of a right angle triangle
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Length of remaining two sides of a Triangle from a given side and its adjacent angles
- Find all angles of a triangle in 3D
- Find all angles of a given triangle
- Find the type of triangle from the given sides
- Find the hypotenuse of a right angled triangle with given two sides
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Find area of triangle if two vectors of two adjacent sides are given
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Find the length of the median of a Triangle if length of sides are given
- Check whether the triangle is valid or not if angles are given
- Check if a triangle of positive area is possible with the given angles
- Check whether triangle is valid or not if sides are given
- Area of a largest square fit in a right angle triangle
- Check whether right angled triangle is valid or not for large sides
- Maximum number of squares that can fit in a right angle isosceles triangle
- Probability of cutting a rope into three pieces such that the sides form a triangle
- Program to find the angles of a quadrilateral
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.