{"id":589,"date":"2024-10-10T22:09:27","date_gmt":"2024-10-10T16:39:27","guid":{"rendered":"https:\/\/codexplained.in\/?p=589"},"modified":"2025-11-24T15:54:17","modified_gmt":"2025-11-24T10:24:17","slug":"converting-decimal-to-octal","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=589","title":{"rendered":"Converting decimal to octal"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\nvoid decimalToOctal(int decimal) {\n    int octal&#x5B;50]; \/\/ Array to store octal digits\n    int index = 0; \/\/ Index for octal array\n\n    \/\/ Continue dividing the decimal number by 8\n    while (decimal &gt; 0) {\n        octal&#x5B;index] = decimal % 8; \/\/ Store the remainder\n        decimal = decimal \/ 8;       \/\/ Update the decimal number\n        index++;                      \/\/ Move to the next index\n    }\n\n    \/\/ Print the octal number in reverse order\n    printf(&quot;Octal equivalent: &quot;);\n    for (int i = index - 1; i &gt;= 0; i--) {\n        printf(&quot;%d&quot;, octal&#x5B;i]); \/\/ Print stored remainders\n    }\n    printf(&quot;\\n&quot;); \/\/ New line after output\n}\n\nint main() {\n    int decimal;\n\n    \/\/ Get user input\n    printf(&quot;Enter a decimal number: &quot;);\n    scanf(&quot;%d&quot;, &amp;decimal); \/\/ Read the decimal number\n\n    \/\/ Call the conversion function\n    decimalToOctal(decimal);\n\n    return 0; \/\/ Indicate successful completion\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Purpose of the Program<\/h3>\n\n\n\n<p>The main goal of this program is to take a decimal (base-10) number as input and convert it to its octal (base-8) representation. This involves breaking down the decimal number into parts that can be expressed using only the digits 0 through 7, which are used in the octal system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Concepts<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Decimal System<\/strong>:\n<ul class=\"wp-block-list\">\n<li>The decimal system is the number system most commonly used in everyday life. It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.<\/li>\n\n\n\n<li>Each digit&#8217;s position in a number represents a power of 10.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Octal System<\/strong>:\n<ul class=\"wp-block-list\">\n<li>The octal system uses eight digits: 0, 1, 2, 3, 4, 5, 6, 7.<\/li>\n\n\n\n<li>Each digit&#8217;s position in an octal number represents a power of 8.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Output:<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nEnter a decimal number: 65\n\nOctal equivalent: 101\n\n<\/pre><\/div><script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script><script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script>","protected":false},"excerpt":{"rendered":"<p>Explanation: Purpose of the Program The main goal of this program is to take a decimal (base-10) number as input and convert it to its octal (base-8) representation. This involves breaking down the decimal number into parts that can be expressed using only the digits 0 through 7, which are used in the octal system. [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":327,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[75],"tags":[],"class_list":["post-589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=589"}],"version-history":[{"count":4,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/589\/revisions"}],"predecessor-version":[{"id":1453,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/589\/revisions\/1453"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/327"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}