# Automorphic Number

## Automorphic Number

A number is said to be automorphic when the result of its square ends with the same digits as the number itself. For instance, 76 is an automorphic number as 76 x 76 = 5776. Likewise, 25 is also an automorphic number as 25 x 25 = 625. The following algorithm and C program will help you test if a number is Automorphic or not.

## Algorithm to test if a number is Automorphic or not

Step 1. Start

Step 2. Input a number from the user.

Step 3. Calculate the square of a number and store result in a variable.

Step 4. Start a loop until n becomes to zero to match values.

Step 5. Check all the digits with its square.

Step 6. Check if n%10 is equal to square % 10, or the last digit of the square

Step 7. Else continue to reduce the number and its square.

Step 8. Return true when all the digits matched.

Step 9. Stop

Read Also: Factorial Of A Number

### C program to test Automorphic Number

```# include <stdio.h>
# include <stdlib.h>
# include <stdbool.h>

//function for calculating automorphic number
bool Automorphic(int number1)
{
int sq_no = number1 * number1;

//While loop to calculate the square of a number
while (number1 > 0)
{
if (number1 % 10 != sq_no % 10)
return false;
number1 /= 10;
sq_no /= 10;
else
return true;
}

}
int main()
{
int auno;
printf("\n\n Check whether a number is an Authomorphic Number or not: \n");
printf(" Enter a Number: ");
scanf("%d",&auno);

if ( Automorphic(auno))
printf(" The given number is an Automorphic Number.\n");
else
printf(" The given number is not an Authomorphic Number.\n");
return 0;
}

```

### Output

```Check whether a number is an Authomorphic Number or not:
Enter a Number: 76
The given number is an Automorphic Number

Check whether a number is an Authomorphic Number or not:
Enter a Number: 25
The given number is an Automorphic Number

Check whether a number is an Authomorphic Number or not:
Enter a Number: 13
The given number is not an Automorphic Number

```