{"id":6224,"date":"2024-02-01T00:01:39","date_gmt":"2024-02-01T08:01:39","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6224"},"modified":"2024-02-08T18:15:14","modified_gmt":"2024-02-09T02:15:14","slug":"positive-negative-positive-negative","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6224","title":{"rendered":"Positive Negative Positive Negative"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9734; &#9734; &#9734;<\/h2>\n<p>One of my pastimes is watching math videos. I was a terrible math student, but I enjoy the videos. Occasionally a concept is presented that I can program in C. This month&#8217;s Exercise covers one of these concepts.<br \/>\n<!--more--><br \/>\nIn this case, <a href=\"https:\/\/www.youtube.com\/watch?v=PQAhC1M93C8\" rel=\"noopener\" target=\"_blank\">the video<\/a> covered presenting values in different bases. The bases include fractions, negative numbers, square roots, and even <em>e<\/em> and &pi;. I find such thought experiments to be stimulating and refreshing.<\/p>\n<p>I wrote about <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4212\">base conversion<\/a> briefly back in 2020, and also about<br \/>\n<a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3344\">Alphabedecimal <\/a>, and I may write about programming in unusual bases in the future. Yet one pattern struck me in the various demonstrations in the video: Occasionally, values in a series alternate between positive and negative.<\/p>\n<p>For example, a series runs: 1, -1, 3, -3, 6, -6, and so on. Programming such a series can be done in a number of ways. Often what&#8217;s necessary is a method to generate output alternating between values of 1, -1, 1, -1, 1, -1, and so on. Coding such a loop is your challenge for this month&#8217;s Exercise:<\/p>\n<p>Write a loop that outputs 14 values, alternating between positive one and negative one. here&#8217;s output from my solution:<\/p>\n<p><code>1<br \/>\n-1<br \/>\n1<br \/>\n-1<br \/>\n1<br \/>\n-1<br \/>\n1<br \/>\n-1<br \/>\n1<br \/>\n-1<br \/>\n1<br \/>\n-1<br \/>\n1<br \/>\n-1<\/code><\/p>\n<p>It seems like a simple task, but as with all programming multiple methods exist to generate the same results. Consider it a brain exercise.<\/p>\n<p>Please try to code a solution on your own before you view <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6232\">my solutions<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes in math, things happen like this: +1 -1 +1 -1 +1 -1 <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6224\">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-6224","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\/6224","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=6224"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6224\/revisions"}],"predecessor-version":[{"id":6250,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6224\/revisions\/6250"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}