Hey Guys,
I got the following code by doing Google search. I have made some changes in this code to suit my self. It's basically for finding Lychrel numbers. The code is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
long long reverse(long long i)
{
int rem;
long long sum = 0;
while(i > 0)
{
rem = i % 10;
sum = (sum * 10) + rem;
i /= 10;
}
return sum;
}
int main()
{
int i, count, ans = 0;
long long next;
for(i = 10; i < 10000; i++)
{
count = 0;
next = reverse(i) + i;
while(count < 50)
{
if(reverse(next) == next)
{
break;
}
else
{
next = reverse(next) + next;
count++;
if(count == 50)
{
ans++;
}
}
}
}
printf("Answer is %d\n",ans);
}
I want to write the code without using BREAK or GOTO keywords, but I'm not able to figure out. If possible please help and give your inputs.
Thanks in advance.