You're online now.

Hurray! you are online now.

# Automorphic number | c programming language

An automorphic number is a number that has the same digit at the end of the square as the given number is an automorphic number. For Example: 25 is a automorphic number.

Let's check that 25 is a automorphic number.
Square of 25 is 625, so end digits of 625 is 25, is same to given number, 25 is automorphic number.

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

int main(){

int n;
printf("Enter the number : ");
scanf("%d", &n);

// Calculate the square
long int sq = n * n;
int d = 10; // divisor
int temp = n, remainder, flag = 0;

while(temp>0){
remainder = sq % d;
if(n == remainder){
flag = 1;
break;
}

temp = temp/10;
d = d * 10;
}

if(flag==1){
printf("%d is an Automorphic Number", n);
}else{
printf("%d is Not an Automorphic Number", n);
}

return 0;
}``````

First created a variable named ‘n’ which stores the input given from the user. Then printed a message for the user so that the user would know what to do now and took input from user through scanf() function. After that we declare soe more variables which have their own different functions. ‘sq’ long int for divisior, ‘temp’ variable is a tempory variable which store the real value of given number by user, ‘remainder’ variable store the value of (the given number of last digit), and flag variable used for the identify. Started a while loop, this loop is valid as long as the given condition is true. As long as the condition is true, it will continue to execute the statement written inside the loop body. When loop condition becomes false then loop will terminated. After this we will check with identifier (flag) that if the value of flag is 1 then we can say that given number is an Automorphic number otherwise we will say that the given number is not an automorphic number. In this way we wrote a program which tells us whether a given number is Automorphic or not.

## Algorithm to check Automorphic number

1. CREATE ‘n’
2. Take input from user.
3. create sq and SET sq = n * n
4. SET d = 10
5. SET temp = n, and CREATE remainder and flag SET flag = 1.
6. REPEAT step 7 and step 8 while (temp > 0)
7. remainder = sq % d;
8. CHECK the (remainder == n) then flag = 1, and break otherwise PERFORM temp = temp / 10 and d = d * 10.
9. CHECK if (flag == 1) PRINT “Number is an automorphic” otherwise PRINT “Number is not an automorphic”
10. EXIT
🖤 0