Given three integers A, B, and C which denote the sides of a triangle, the task is to check that the triangle is a right-angled, acute-angled, or obtuse-angled triangle. Examples:
Input: A = 1, B = 4, C = 3 Output: Obtuse-angled Triangle Explanation: Triangle with the sides 1, 2 and 3 is an obtuse-angled triangle Input: A = 2, B = 2, C = 2 Output: Acute-angled Triangle Explanation: Triangle with the sides 2, 2, and 2 is an acute-angled triangle
Approach: The idea is to use the facts from the cosine law to check the type of triangle using these formulae –
It generalizes the Pythagorean Theorem, which states that for a right-angled triangle square of the hypotenuse is equal to the sum of squares of the base and height of the triangle, which is Similarly, It can be observed that For acute-angled triangle
For Obtuse-angled triangle
Below is the implementation of the above approach:
Please Login to comment...