{"id":7173,"date":"2025-10-01T00:01:22","date_gmt":"2025-10-01T07:01:22","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7173"},"modified":"2025-10-08T14:53:32","modified_gmt":"2025-10-08T21:53:32","slug":"herons-formula","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7173","title":{"rendered":"Heron&#8217;s Formula"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9734; &#9734;<\/h2>\n<p>The only aspect of math I enjoyed in school was geometry. Trigonometry was a close second. I found the study fascinating and did well; I received a B in that class as opposed by my usual C- or D.<br \/>\n<!--more--><br \/>\nOne thing I missed (or slept through) was Heron&#8217;s Formula, which is used to calculate the area of a triangle.<\/p>\n<p>The area of a triangle is defined as one-half the base times the height, or &half;<em>bh<\/em>. I drew an illustration in Figure 1 because I&#8217;ve had some extra time this morning.<\/p>\n<div id=\"attachment_7178\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-7178\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2025\/10\/1001-figure1.png\" alt=\"Triangle\" width=\"400\" height=\"372\" class=\"size-full wp-image-7178\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2025\/10\/1001-figure1.png 400w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2025\/10\/1001-figure1-300x279.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2025\/10\/1001-figure1-323x300.png 323w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><p id=\"caption-attachment-7178\" class=\"wp-caption-text\">Figure 1. Calculating the area of any triangle: (base*height)\/2<\/p><\/div>\n<p>Oh, lots of fun can be had with triangles, especially right triangles. But weirdo triangles like the one shown in Figure 1 present an interesting problem when it comes to finding the area. I suppose you could &#8220;rotate&#8221; the triangle so that one side was flat. But other than using a ruler, obtaining the area isn&#8217;t obvious.<\/p>\n<p>What Heron (also known as Hero of Alexandria) did was to concoct a formula whereby you can calculate the area of a triangle when you know the length of each side. To me, this approach seems whacky, but it works. Here is Heron&#8217;s formula:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/1e8e1851a05e4cd4e764ec7dbe96c477989fcde3\" alt=\"Heron's Formula\" \/><\/p>\n<p>Variables <em>a<\/em>, <em>b<\/em>, and <em>c<\/em> represent the lengths of the three sides of a triangle, as shown in Figure 1. Variable <em>s<\/em> is the semi-perimeter of the triangle, calculated by using this formula:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/ed2c4193212526a50585182f301e85e2f1cdfde8\" alt=\"Semi perimeter calculation\" \/><\/p>\n<p>As the name states, the semi-perimeter is the total of the three sides lengths divided by two. This value is plugged into Heron&#8217;s Formula to obtain the triangle&#8217;s area.<\/p>\n<p>I&#8217;m certain that lots of interesting mathematical magic is happening to justify how and why Heron&#8217;s Formula works. This problem isn&#8217;t the one you need to solve. No, your task for this exercise is to write a program that accepts the lengths of three sides of a triangle and generates the triangle&#8217;s area as output.<\/p>\n<p>Here is a sample run of my solution:<\/p>\n<p><code>Input the length of side A: 12<br \/>\nInput the length of side B: 16<br \/>\nInput the length of side C: 20<br \/>\nSemi-perimeter is 24.00<br \/>\nThe triangle's area is 96.00 units<\/code><\/p>\n<p>Coding the solution is the challenge, but a secondary challenge is to input proper values to represent a true triangle. You just can&#8217;t type in any values, as they may not result in a triangular shape. The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Heron%27s_formula\" target=\"_blank\">Wikipedia page<\/a> on Heron&#8217;s Formula features an area calculator. Use it to test values and confirm that the data input creates triangle and to check your answer.<\/p>\n<p><a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7189\">Click here<\/a> to view my solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculate the area of a triangle by inputting the lengths for its three sides. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7173\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7173","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7173"}],"version-history":[{"count":11,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7173\/revisions"}],"predecessor-version":[{"id":7207,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7173\/revisions\/7207"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}