Types of trianglesSolving CodeAbbey Pythagorean Theorem challenge
A triangle is a 3-sided polygon sometimes (but not very commonly) called the trigon. Every triangle has three sides and three angles, some of which may be the same. The sides of a triangle are given special names in the case of a right triangle, with the side opposite the right angle being termed the hypotenuse and the other two sides being known as the legs. All triangles are convex and bicentric. That portion of the plane enclosed by the triangle is called the triangle interior, while the remainder is the exterior.
An triangle is said to be acute if all three of its angles are all acute, a triangle having an obtuse angle is called an obtuse triangle, and a triangle with a right angle is called right. A triangle with all sides equal is called equilateral, a triangle with two sides equal is called isosceles, and a triangle with all sides a different length is called scalene. A triangle can be simultaneously right and isosceles, in which case it is known as an isosceles right triangle.
Challenge CodeAbbey Pythagorean Theorem
On this task we need to tell, based on an algorithm if the triangle given is right, acute or obtuse. For acute triangle its longest side is shorter than hypotenuse should be, for obtuse triangle its longest side is longer than hypotenuse should be and for right for obtuse triangle its longest side is the same length as the hypotenuse.
On the first line we receive the number of test cases, on next lines the sides of the triangles, with their longest side at the end. We need to answer with letters if the triangle is Acute, Obtuse or Right.
input data: 3 6 8 9 9 12 15 16 12 22
answer: A R O
We calculate first the hypotenuse with the first 2 sides
let rec hypo a b = hypot a b;
Then we compare with the longest side
1 2 3 4 5 6 7
if float_of_int c > hy then Printf.printf "O " else if float_of_int c < hy then Printf.printf "A " else Printf.printf "R "
Computer Engineer, Security+
"Be formless, shapeless like water" Bruce Lee