C Program to Check Whether a Given Number is Automorphic (Cyclic) or Not

A number is called Automorphic or Cyclic number if and only if its square ends in the same digits as the number itself.

For Examples: 52 = 25, 62 = 36, 762 = 5776, 3762 = 141376

Program


#include<stdio.h>
#include<conio.h>

int main()
{
 long int number, square, flag=1;
 clrscr();
 printf("Enter integer number:\n");
 scanf("%ld", &number);
 square = number * number;
 while(number!=0)
 {
  if(square%10 != number%10)
  {
   flag=0;
   break;
  }
  number = number/10;
  square = square/10;
 }
 if(flag==1)
 {
  printf("AUTOMORPHIC");
 }
 else
 {
  printf("NOT AUTOMORPHIC");
 }
 getch();
 return 0;
}

Output of above program :

Run 1:
-----------------
Enter integer number:
5 ↲
AUTOMORPHIC

Run 2:
-----------------
Enter integer number:
76 ↲
AUTOMORPHIC

Run 3:
-----------------
Enter integer number:
7 ↲
NOT AUTOMORPHIC


Note: ↲ indicates ENTER is pressed.