2
votes

Hi there I need to write algorithm which reads the largest angle of a triangle and the three sides from left, right then bottom. Then based on those results it outputs the specific angle/side triangle.

The specific triangles are acute scalene, right scalene, obtuse scalene, acute isosceles, right isosceles, obtuse isosceles and an equilateral triangle.

We have to write a basic algorithm in pseudocode. I honestly have no idea where to start, any help would be appreciated.

3
I suggest starting out by drawing a decision tree - samgak

3 Answers

0
votes

You just need to come up with a series of tests to apply to the triangle. Imagine you are designing the layout of a factory, and these triangles are coming down a conveyor belt past a series of workers. Each worker can check something about the triangle, and then put it into a bin based on its type or move it onto another conveyor belt to go past more workers who will do more tests on it.

For example, you can easily test if it is equilateral by checking if all the sides are equal and if so you can just output that and stop there.

If not, then it must be scalene or isoceles.

If the largest angle is smaller than 90 degrees, it's acute. If it's equal to 90 degrees then it's a right angled triangle, if it's greater than 90 degrees then it's obtuse.

If two of the sides are of equal length then it's isoceles, otherwise it's scalene.

Start by sketching out a decision tree or flowchart based on these criteria. Then turn it into pseudocode.

0
votes

You should be able to use the law of sines and then do a case by case analysis to figure out which kind of triangle your given triangle is.

0
votes

Start with the easy one. An equilateral triangle has 3 equal sides.

So:

   function isEquilateral(left, right, bottom) {
      return left === right == bottom;
   );