I was solving this problem (https://projecteuler.net/problem=55) and I couldn't get it right. The answer was 249 and my code was giving 136. I don't know what is wrong with my code. Here is my code:
#include <stdio.h>
long long reverse(long long n)
{
long long a=0, t=n, temp;
while (t)
{
temp=t%10;
a=a*10+temp;
t=t/10;
}
return a;
}
bool palindromic(long long n)
{
return reverse(n)==n;
}
bool lychrel(long long n)
{
long long k=n;
for (int i=0; i<50; i++)
{
k+=reverse(k);
if (palindromic(k)) return false;
}
return true;
}
int main()
{
int i, count=0;
for (i=1; i<10000; i++)
if (lychrel(i)) count++;
printf("%d", count);
return 0;
}
Thanks in advance!