SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to find automorphic number
C program to find automorphic number
Output:
Enter the number to check whether automorphic number or not: 890625
890625 is an automorphic number.
Implementation:
/* An automorphic number is a number whose square ends in the same digits as the number itself. For example: 5 * 5 = 25 6 * 6 = 36 76 * 76 = 5776 890625 * 890625 = 793212890625 So, 5, 6, 7, 76 and 890625 are all automorphic numbers */ #include
#include
#include
#include
typedef unsigned long long int ll; ll checkautomorphic(ll n,ll square) { ll flag=0; while(n) { if(n%10 == square%10) { n/=10; square/=10; } else { flag=1; break; } } if(flag) { return 0; } else { return 1; } } int main(void) { ll n; ll square; printf("Enter the number to check whether automorphic number or not:\n"); scanf("%llu",&n); square = n * n; if(checkautomorphic(n,square)) { printf("%llu is an automorphic number\n",n); } else { printf("%llu is not an automorphic number\n",n); } return 0; }
PREVIOUS
NEXT
HOME