First we need to understand What is Automophic numbers? A number whose square's last degit(s) are equal to that number. Some example of automorphic number is 1, 5, 6, 25, 76
For example
5 ^2 = 25
So here square of 5 is 25 and last digit of 25 is 5. And its equal to 5.
Source Code to check Automorphic number
#include<stdio.h>
void main()
{
long int n,no=0,s,rem=0,ans=0,temp;
clrscr();
printf("Enter a number: ");
scanf("%ld",&n);
no=n;
s=n*n;
temp=10;
while(n>0)
{
rem=s%temp;
if(no==rem)
{
ans=1;
break;
}
n=n/10;
temp=temp*10;
}
if(ans==1)
{
printf("no is automorphic");
}
else
{
printf("no is not automorphic");
}
getch();
}

0 comments:
Post a Comment