{"id":6733,"date":"2025-01-01T00:01:52","date_gmt":"2025-01-01T08:01:52","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6733"},"modified":"2025-01-08T19:53:51","modified_gmt":"2025-01-09T03:53:51","slug":"emulating-the-modulus-operator","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6733","title":{"rendered":"Emulating the Modulus Operator"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9734; &#9734;<\/h2>\n<p>I think any kid learning math in school knows what a remainder is, but few understand (or are taught) what a modulus is. It obtains the remainder of one value divided by another, specifically a larger value divided by a smaller value. In C programming, the <code>%<\/code> (modulo) operator performs this calculation. But what if the C language lacked a modulo operator?<br \/>\n<!--more--><br \/>\nYour task for this month&#8217;s Exercise is to emulate the modulus operator. Or is it the modulo operator? Whatever. Write a function, <em>mod()<\/em>, that accepts two integers as an argument and returns the remainder for the first divided by the second &mdash; the modulus.<\/p>\n<p>Here is sample output from my solution:<\/p>\n<p><code>Enter two integers separated by a space: 33 7<br \/>\n% operator: 33 % 7 = 5<br \/>\nmod() function: 33 % 7 = 5<\/code><\/p>\n<p>As shown above, your program should prompt for two integer values. The next two lines show output manipulating the values. The first uses the <code>%<\/code> operator, the second the <em>mod()<\/em> function. Both results are the same, which proves the function&#8217;s success.<\/p>\n<p>Please try this exercise on your own. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6755\">Click here<\/a> to view my solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What would happen should the modulus operator (%) just up and disappear! <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6733\">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-6733","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\/6733","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=6733"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6733\/revisions"}],"predecessor-version":[{"id":6812,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6733\/revisions\/6812"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}