AUTOMORPHIC NUMBER OR NOT
Consider the following I/O samples.
SAMPLE INPUT: 5
SAMPLE OUTPUT: AUTOMORPHIC NUMBER
A number is called a AUTOMORPHIC NUMBER if and only if the square of the given number ends with the same number itself.
76^2 = 5776
int main()
{
int num, sqr, temp, last,count=0,den;
scanf("%d",&num);
sqr = num*num;
temp = num;
while(temp>0)
{
count++;
temp = temp/10;
}
den = floor(pow(10,count));
last = sqr % den;
if(last == num)
printf("Automorphic number");
else
printf("Not Automorphic");
return 0;
}
If you have any feedback about this article and want to improve this, please write to nivisonu23@gmail.com
Comments
Post a Comment