(41C) Area of Triangle (SSS)
|
11-10-2018, 08:53 PM
(This post was last modified: 11-10-2018 09:33 PM by Dieter.)
Post: #3
|
|||
|
|||
RE: (41C) Area of Triangle (SSS)
(11-10-2018 12:20 PM)Gamo Wrote: This program tell what kind of Triangle then give answer of the area. Sorry, but this doesn't work. Try a=5, b=4 and c=3 and it returns "SCALENE". The three sides must be entered in a specific order. For instance, for right-angled triangles the largest side has to be c. Maybe you should add this in the instructions. Also the LBL 02 part can be removed – the test whether R01=R02 has already been done before. So you may remove that section and replace "GTO 02" with "GTO 03". (11-10-2018 03:22 PM)Albert Chan Wrote: If the sides are sorted, a >= b >= c, Kahan's formula is more accurate. A sorted order also faciliates the tests for the different kinds of triangles.Here is a program that puts the largest side in R01 and the smallest in R03. It should work for any input order, and it also uses the Kahan formula. Code: 01 LBL "AREA" The program does its tests in the following order, assuming a ≥ b ≥ c. 1. Check if a=c. This means that a=b=c => equilateral triangle 2. Check if a=b or b=c. If true, it's a isosceles triangle Note: line 49...55 are a kind of poor man's "OR" test A conventional approach would even be slightly shorter, but it looks more fancy this way ;-) 3. Check if a²=b²+c². In this case it's a right-angled triangle 4. If none of the tests was true it's a scalene triangle Examples: Code: [XEQ] "AREA" ENTER A↑B↑C Press backspace [←] to see the area. (11-10-2018 03:22 PM)Albert Chan Wrote: Try Kahan's example: For this case the result with the above program is correctly rounded to 9,999999990. Well, almost – the true result is 9,9999 99989 49999 99... so that the ten-digit value should better be rounded down to ...989. ;-) Dieter |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(41C) Area of Triangle (SSS) - Gamo - 11-10-2018, 12:20 PM
RE: (41C) Area of Triangle (SSS) - Albert Chan - 11-10-2018, 03:22 PM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-10-2018 08:53 PM
RE: (41C) Area of Triangle (SSS) - Albert Chan - 11-12-2018, 02:55 PM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-12-2018, 08:28 PM
RE: (41C) Area of Triangle (SSS) - Albert Chan - 11-12-2018, 10:33 PM
RE: (41C) Area of Triangle (SSS) - Gamo - 11-11-2018, 05:04 AM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-11-2018, 07:53 AM
RE: (41C) Area of Triangle (SSS) - Gamo - 11-11-2018, 12:23 PM
RE: (41C) Area of Triangle (SSS) - Dieter - 11-11-2018, 04:25 PM
RE: (41C) Area of Triangle (SSS) - Albert Chan - 11-12-2018, 01:32 AM
RE: (41C) Area of Triangle (SSS) - Albert Chan - 11-16-2018, 03:33 AM
RE: (41C) Area of Triangle (SSS) - Albert Chan - 12-04-2019, 03:03 PM
|
User(s) browsing this thread: 1 Guest(s)