Given three Cartesian coordinates, the task is to check if a right-angled triangle can be formed by the given coordinates. If it is possible to create a right-angled triangle, print Yes. Otherwise, print No.
Input: X1=0, Y1=5, X2=19, Y2=5, X3=0, Y3=0 Output: Yes Explanation: Length of side connecting points (X1, Y1) and (X2, Y2) is 12. Length of side connecting points (X2, Y2) and (X3, Y3) is 15. Length of side connecting points (X1, Y1) and (X3, Y3) is 9. 122 + 92 = 152. Therefore, a right-angled triangle can be made.
Input: X1=5, Y1=14, X2=6, Y2=13, X3=8, Y3=7 Output: No
Approach: The idea is to use the Pythagoras Theorem to check if a right-angled triangle is possible or not. Calculate the length of the three sides of the triangle by joining the given coordinates. Let the sides be A, B, and C. The given triangle is right-angled if and only if A2 + B2 = C2. Print Yes if the condition holds true. Otherwise, print No.
Below is the implementation of the above approach:
Please Login to comment...