{"id":7257,"date":"2025-12-01T00:01:55","date_gmt":"2025-12-01T08:01:55","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7257"},"modified":"2025-12-08T14:02:28","modified_gmt":"2025-12-08T22:02:28","slug":"which-is-greatest","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7257","title":{"rendered":"Which is Greatest?"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9734;<\/h2>\n<p>One of the first functions many C programmers code is <em>max()<\/em>. It returns the largest of two values. Though this operation can also take place by using a simple <em>if-else<\/em> comparison, it&#8217;s a great way to teach how functions work and test various comparison operators. But this task isn&#8217;t the challenge for this month&#8217;s exercise.<br \/>\n<!--more--><br \/>\nA few months back, the <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7173\">Exercise<\/a> was to code Heron&#8217;s Formula. This formula uses the lengths of a triangle&#8217;s three sides to calculate its area.<\/p>\n<p>In the post, I noted that inputting the three side lengths was something that my solution didn&#8217;t validate. A <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7173#comment-815\">comment from Chris Webb<\/a> stated that you can validate a triangle&#8217;s proportions by ensuring that the sum of the two shorter sides is greater than the longest side. This statement got me thinking about measuring the three side values input and determining which is the largest. The process works like the old <em>max()<\/em> problem, but with three values instead of two.<\/p>\n<p>Your challenge for this month&#8217;s Exercise is to write a function, <em>greatest()<\/em>. This function is fed three random values in the range of 2 to 25. It returns the largest of these three values.<\/p>\n<p>Here&#8217;s a sample run from one of my solutions:<\/p>\n<p><code>The greatest of 7, 21, and 16 is 21<\/code><\/p>\n<p>Yes, I wrote two solutions, which is part of this challenge as well: Craft two versions of the <em>greatest()<\/em> function. The easy version uses <em>if<\/em> tests. The more difficult version uses the ternary operator. If you can, try  to craft a single statement that generates and returns the proper result. Have fun!<\/p>\n<p><a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7274\">Click here<\/a> to view my solutions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Finding the largest value, or taking the old <em>max()<\/em> function to the third degree. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7257\">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-7257","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\/7257","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=7257"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7257\/revisions"}],"predecessor-version":[{"id":7308,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7257\/revisions\/7308"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}