{"id":2554,"date":"2017-06-17T00:01:58","date_gmt":"2017-06-17T07:01:58","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=2554"},"modified":"2017-06-10T09:16:45","modified_gmt":"2017-06-10T16:16:45","slug":"the-gazinta-function","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=2554","title":{"rendered":"The &#8220;Gazinta&#8221; Function"},"content":{"rendered":"<p>Division is the last of the four basic arithmetic operations taught. Addition is easiest, followed by subtraction. Multiplication is merely aggressive addition. Division is a weird un-multiplication combined with subtraction thing, which is probably why educators save the concept for last.<br \/>\n<!--more--><br \/>\nIn programming, as in all computerdom, division is handled by the <code>\/<\/code> operator. It&#8217;s one of the common symbols used to express division, as illustrated in Figure 1.<\/p>\n<div id=\"attachment_2560\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2560\" src=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/0617_figure1-gazinta.png\" alt=\"\" width=\"500\" height=\"115\" class=\"size-full wp-image-2560\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/0617_figure1-gazinta.png 500w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/0617_figure1-gazinta-300x69.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><p id=\"caption-attachment-2560\" class=\"wp-caption-text\">Figure 1. Way to express division.<\/p><\/div>\n<p>The symbol on the far right in Figure 1 isn&#8217;t used in higher mathematics, or even in some countries. It&#8217;s the long division construction, popular in American grammar schools, and it&#8217;s what I call the <em>gazinta<\/em>. Also, it reads backwards from the other functions.<\/p>\n<p>For example, the first three expressions in Figure 1 say the same thing: 5 divided by 4. The fourth says, &#8220;4 goes into 5,&#8221; which is still &#8220;5 divided by 4,&#8221; but the way I remember it is to say &#8220;goes into&#8221; or &#8220;gazinta.&#8221;<\/p>\n<p>The first three forms shown in Figure 1 express ratios, which is really what division is all about. The fourth form &mdash; the gazinta &mdash; produces a result and a remainder. So the ratio of 5\/4 is 1.25, but the gazinta is 1 with 1 remainder.<\/p>\n<p>The C language features a gazinta function, disappointingly called <em>div()<\/em> and not <em>gazinta()<\/em>. The function is defined in the <code>stdlib.h<\/code> header.<\/p>\n<p>The <em>div()<\/em> function requires two arguments, a numerator and a denominator. The numerator is the number on top the fraction (or ratio). The denominator is on the bottom. So in 5\/4, the value 5 is the numerator and 4 is the denominator. For a gazinta, the denominator appears first, then the numerator is inside the &#10188; thing.<\/p>\n<p>At this point, you&#8217;re probably wondering why bother with a <em>div()<\/em> function, and why place it in <code>stdlib.h<\/code> and not the <code>math.h<\/code> header? That&#8217;s because the <em>div()<\/em> function doesn&#8217;t just divide the numbers. Instead it returns a <em>div_t<\/em> structure (also defined in <code>stdlib.h<\/code>). The <em>div_t<\/em> structure contains two <em>int<\/em> elements: <code>quot<\/code> and <code>rem<\/code> for quotient and remainder, respectively.<\/p>\n<p>So just like the gazinta, the <em>div()<\/em> function divides two values, returning the quotient and remainder. Here&#8217;s sample code:<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n\r\nint main()\r\n{\r\n    div_t result;\r\n    int n,d;\r\n\r\n    printf(\"Enter the numerator: \");\r\n    scanf(\"%d\",&amp;n);\r\n    printf(\"Enter the denominator: \");\r\n    scanf(\"%d\",&amp;d);\r\n\r\n    result = div(n,d);\r\n    printf(\"%d divided by %d equals %d with %d remaining.\\n\",\r\n            n,\r\n            d,\r\n            result.quot,\r\n            result.rem);\r\n\r\n    return(0);\r\n}<\/pre>\n<p>A <em>div_t<\/em> structure <code>result<\/code> is created at Line 6. The numerator and denominator values are obtained in Lines 9 through 12. The <em>div()<\/em> function is called at Line 14, and the results displayed in a <em>printf()<\/em> statement that spans Lines 15 through 19.<\/p>\n<p>Here&#8217;s a sample run:<\/p>\n<pre><code>Enter the numerator: 5\r\nEnter the denominator: 4\r\n5 divided by 4 equals 1 with 1 remaining.<\/code><\/pre>\n<p>This type of code doesn&#8217;t deal with real numbers (<em>float<\/em> values) because, just like long division, all values are integers. It&#8217;s also different from the modulus operator (<code>%<\/code>) because two values are generated, not just the remainder.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Division involves three terms: numerator, denominator, and gazinta. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2554\">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":[2],"tags":[],"class_list":["post-2554","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2554","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=2554"}],"version-history":[{"count":8,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2554\/revisions"}],"predecessor-version":[{"id":2574,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2554\/revisions\/2574"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}