Thursday 31 August 2017

C PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS AUTOMORPHIC OR NOT.

An automorphic number is a number whose square contains the same number as last digits or digit. Example :, 52 = 25,62 = 36

Program:


#include <stdio.h>
main()
{
               int i,n,y,flag=0;
               printf("enter a number");
               scanf("%d",&n);
               y=n*n;
               while(n>0)
               {
                              if(n%10 == y%10)//if units place digits are same
                              {
                                             n=n/10;
                                             y=y/10;
                              }
                              else
                              {
                                             flag=1;
                                             break;
                              }
               }
               if(flag==0)
                              printf("given number is automorphic");
               else
                              printf("given number is not automorphic");
}

No comments:

Post a Comment