Run this program (or add the according printf()-call inside your loop) and you will notice that after the 40th iteration you have an overflow and all following calculations are wrong:
Code:
#include <stdio.h>
unsigned long long palindrome(unsigned long long n);
int main(void)
{
int i;
unsigned long long number = 196;
for (i = 0; i < 50; i++)
{
printf("%3d %22llu\n", i, number);
number += palindrome(number);
}
return 0;
}
unsigned long long palindrome(unsigned long long n)
{
unsigned long long p = 0;
while (n > 0)
{
p *= 10;
p += n % 10;
n /= 10;
}
return p;
}
Bye, Andreas