{"id":7916,"date":"2026-12-01T00:01:18","date_gmt":"2026-12-01T08:01:18","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7916"},"modified":"2026-11-28T14:50:16","modified_gmt":"2026-11-28T22:50:16","slug":"comparing-without-a-conditional-statement","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7916","title":{"rendered":"Comparing Without a Conditional Statement"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9733;<\/h2>\n<p>The challenge for <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7844\">last month&#8217;s Exercise<\/a> was to generate repeated output without using a looping statement. The solution is to use recursion, though this choice is obvious only to experienced programmers who know about recursion. The challenge for this month&#8217;s exercise is far more devious, hence the four stars.<br \/>\n<!--more--><br \/>\nA conditional statement in C programming is one that evaluates two expressions. The common one is the <em>if<\/em> keyword, but the <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2542\"><code>?:<\/code> operator<\/a> also counts. Mixed in are the comparison operators: ==, !=, &lt;, &gt;, &lt;=, and &gt;=. It&#8217;s also possible to use <em>if<\/em> or <code>?:<\/code> with a single expression, providing that the expression evaluates TRUE (non-zero) or FALSE (zero).<\/p>\n<p>Your task is to write a program that generates a random value, 0 through 99. The program then outputs whether the value is odd or even without using any of the standard comparison tools.<\/p>\n<p>Here are a few sample runs from my solution:<\/p>\n<pre>The value 86 is even\r\n\r\nThe value 19 is odd\r\n\r\nThe value 44 is even\r\n\r\nThe value 19 is odd<\/pre>\n<p>Working with this problem, I developed two approaches though they both rely upon the same mechanism to generate the &#8220;odd&#8221; or &#8220;even&#8221; text output. I will also be exploring further ways to fake comparisons in C later this mornth.<\/p>\n<p>This exercise can be a tough one. You really need to think outside of the box. And, yes, your solution cannot use <em>if<\/em> or <code>?:<\/code> or any of the comparison operators to generate the output.<\/p>\n<p>I post my solution in a week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes, it&#8217;s more than possible to make a decision without using a conditional statement. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7916\">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-7916","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\/7916","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=7916"}],"version-history":[{"count":3,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7916\/revisions"}],"predecessor-version":[{"id":7927,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7916\/revisions\/7927"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}