I have a simple program that finds automorphic numbers up to given number. The problem is it just finds the number which square parameter is bound of int.
for example : 90625 x 90625 = 8212890625 but program could't find it.
Question : What is the problem with long type here? It act like int. Is there a cast to int for the square parameter anywhere of the code?
#include <stdio.h>
int main(void)
{
int n;
long i;
printf ("Enter a value:\n") ;
scanf ("%d",&n) ;
printf ("Automorphic numbers:\n") ;
for (i=1L ; i<=n ; i = i+1L)
{
long square = i*i ;
if (square % 10L == i || square % 100L == i || square % 1000L == i || square % 10000L == i || square % 100000L == i || square % 1000000L == i || square % 10000000L == i)
printf ("%li\n", i) ;
}
}