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. Examples:
Approach to check if triangle exists and finding Sides: 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. c-b = 2 & c+b = (a2)/2 Hence, c = (a2)/4 + 1; b = (a2)/4 - 1; This works when a is even.
Below is the implementation of the above approach: C++
Java
Python 3
C#
PHP
Javascript
Output: Side b = 35, Side c = 37 Angles are A = 18.9246, B = 71.0754, C = 90 Time Complexity: O(1), since there is no loop or recursion. How do you find the third angle of a triangle given 2 sides?All you have to do is add up the measurements of the sides you know (30° + 90° = 120°) and subtract that number from 180°. So, 180° - 120° = 60°. The measurement of that third angle is 60°.
|