











C++ Program to check whether a number is an Automorphic number or not
Program to check whether a number is an Automorphic number or not
Here we will discuss how to check whether a number is an Automorphic number or not using C++ programming language.
An automorphic number is a number in which the last digits of the square of the number is equal to the number itself.
To check for Automorphic number, first find the square of the number. Then compare the last digits of the square by the number digit by digit and then are equal then it’s an Automorphic number else not.
Example: 25
Square of 25 = 625
As we can see the last digits of square equals to the number, so 25 is an Automorphic number.




Algorithm:-
- User gives an input(number).
- Input is stored in an int type variable say num.
- The square of num is found and stored in another variable say sq
- num is stored in another variable called store for future use.
- A do while loop is started
- If the last digit of the num and sq are not equal then turn flag = 1 and break the loop
if(num%10!=sq%10)
flag=1;
break;
2. Divide both num and sq by 10.
num=num/10;
sq=sq/10;
3. The loop will run till num is greater than 0.
while(num>0)
6. If flag is equal to 1 then the number is not an automorphic number.
Otherwise the number is an Automorphic number.
C++ Code:-
- Positive or Negative number: C | C++ | Java
- Even or Odd number: C | C++ | Java
- Sum of First N Natural numbers: C | C++ | Java
- Sum of N natural numbers: C | C++ | Java
- Sum of numbers in a given range: C | C++ | Java
- Greatest of two numbers: C | C++ | Java
- Greatest of the Three numbers: C | C++ | Java
- Leap year or not: C | C++ | Java
- Prime number: C | C++ | Java
- Prime number within a given range: C | C++ | Java
- Factorial of a number: C | C++ | Java
- Sum of digits of a number: C | C++ | Java
- Reverse of a number : C | C++ | Java
- Palindrome number: C | C++ | Java
- Armstrong number : C | C++ | Java
- Armstrong number in a given range : C | C++ | Java
- Fibonacci Series upto nth term : C | C++ | Java
- Factorial of a number : C | C++ | Java
- Power of a number : C | C++ | Java
- Factor of a number : C | C++ | Java
- Strong number : C | C++ | Java
- Perfect number : C | C++ | Java
- Automorphic number : C | C++ | Java
- Harshad number : C | C++ | Java
- Abundant number : C| C++ | Java
- Friendly pair : C | C++ | Java


Login/Signup to comment