{"id":7328,"date":"2026-01-01T00:01:43","date_gmt":"2026-01-01T08:01:43","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7328"},"modified":"2026-01-08T21:03:57","modified_gmt":"2026-01-09T05:03:57","slug":"is-it-a-real-triangle","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7328","title":{"rendered":"Is It a &#8220;Real&#8221; Triangle?"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9734; &#9734;<\/h2>\n<p>Back in October, the <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7173\">C programming Exercise<\/a> was to code Heron&#8217;s Formula. The challenge required the user to input three values, one for each side of the triangle. But, as I learned since, a triangle must have specific side length ratios for it to be a valid triangle.<br \/>\n<!--more--><br \/>\nCall me math-challenged.<\/p>\n<p>Anyhoo, it turns out that for a triangle to be a triangle the length of the longest side must be less than the combined lengths of the other two sides. Further (!) I learned that this rule doesn&#8217;t apply to an isosceles triangle or an equilateral triangle, both of which are valid ways to stick three lines together.<\/p>\n<p>(I might also add that the longest side of a triangle is called the hypotenuse only when dealing with a right triangle.)<\/p>\n<p>The challenge for this month&#8217;s Exercise is to write code that generates three random numbers in the range of 2 to 25. Examine each of these values to determine whether they could be the lengths of the sides of a valid triangle. Test for an equilateral triangle. Test for an isosceles triangle. Test for an otherwise valid triangle and note the longest side. Test for an invalid triangle.<\/p>\n<p>Fortunately, you don&#8217;t need to test whether the triangle is acute, obtuse, or right &mdash; though I&#8217;d be duly impressed if you take the challenge that far.<\/p>\n<p>Here is output from a few sample runs of my solution:<\/p>\n<pre>14 - 7 - 7 is an isosceles triangle\r\n\r\n17 - 3 - 16 is a valid triangle\r\n17 is the longest side\r\n\r\n2 - 10 - 22 is not a valid triangle<\/pre>\n<p>Please try this exercise on your own before you peek at <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7337\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Triangles have rules, you know. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7328\">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-7328","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\/7328","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=7328"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7328\/revisions"}],"predecessor-version":[{"id":7354,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7328\/revisions\/7354"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}