Automorphic Number or Not | C Program

C program to check automorphic number or not

Write a C program to find number is  Automorphic number or not.

In this program we have to find the number is Automorphic number or not using C programming. Basically automorphic number is a number whose square ends with the same digits as number itself.

Automorphic Number in C Programming

Example:

  • 5=(5)2=25
  • 6=(6)2=36
  • 25=(25)2=625
  • 76=(76)2=5776
  • 376=(376)2=141376

These numbers are automorphic number.

  • Automorphic number : C | C++ | Java
automorphic number or not in c

Working:-

Step 1- Enter the number to be check.

Step 2- store the number in temporary variable.

Step 3- find the square  of a given number and display it.

Step 3- Initialize the while loop until the number is not equal to zero

      (i) Calculate the remainder of the temp,divided with the 10 and store in digit.

      (ii) divide the number with the 10 and store in the number.

Step 4- find modules of square with count and compare with temp

Step 5-if it is true display Automorphic  or else not a Automorphic number

Step 6- Stop.

 

C Program:-

#include<stdio.h>

int checkAutomorphic(int num)
{
int square = num * num;

while (num > 0)
{
if (num % 10 != square % 10)
return 0;

// Reduce N and square
num = num / 10;
square = square / 10;
}
return 1;
}

int main()
{
//enter value
int num;
scanf("%d",&num);

//checking condition
if(checkAutomorphic(num))
printf("Automorphic");
else
printf("Not Automorphic");
return 0;
}

Output:-

6
Automorphic

12
Not Automorphic

376
Not Automorphic