By SHUBHAM GARG

This article aims to check whether a number is Automorphic (a number whose last digits of its square is equal to the number itself) or not, implemented in C++.

Hola Coders!

Automorphic Number is a number whose last digits of its square is equal to the number itself.

The steps to check the number are illustrated below:

1. Firstly square the number.

2. Check the last digits of the square one by one. If the square has same set of last digits as the original number then it's an Automorphic number.

For example:

Consider the number 25. After squaring, we obtain the number 625. Then on checking the last digits of 25 and 625, we've found that the last digits of 6**25** matches with **25. **Hence, 25 is an** Automorphic number.**

//C++ Program to check whether a number is Automorphic number or not #include using namespace std; //main program int main() { int n,flag =0; cout<<"Enter the number to check: "; //user input cin>>n; int sq = n*n; int temp = n; //check for automorphic number while(n>0) { if(n%10 != sq%10) { flag=1; break; } n/=10; sq/=10; } if(flag) cout<<temp<<" is not an Automorphic number."; else cout<<temp<<" is an Automorphic number."; return 0; }

**Happy Learning!**

Submitted by SHUBHAM GARG (Shubham)

Download packets of source code on Coders Packet