C Program to Check Automorphic (Cyclic) Number

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

Automorphic or Cyclic Number Examples: 52 = 25, 62 = 36, 762 = 5776, 3762 = 141376

This C Program checks whether a given number by user is automorphic number or not.

C Source Code: Check Automorphic (Cyclic) Number


#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;
}

Check Automorphic (Cyclic) C Program Output

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.