MATLAB: Hey. the problem statement is find lychrel numkbers upto 10000.i have done the coding accordingly but it is showing random characters in output..plz help guys

lychrel numbers

clc;close all;
c=0;
k=0;
for i=10:1:9999
if i == fliplr(i)
disp (['The string, ' i ', is a palindrome.'])
else
disp (['The string, ' i ', is not a palindrome.'])
num1=i;
for j=1:50:1
reverse=0;
while num1 > 0
t = mod(num1,10);
reverse = 10*reverse+t;
num1 = (num1-t)/10;
end
k=num1+reverse;
if k == fliplr(k)
disp (['The string',k,' is a palindrome after folloowing iteration',j])
end
end
c=c+1;
disp(c)
end
end

Best Answer

I suggest that you use the debugger to execute your code one line at a time and observe how it behaves and how the variables change. You should quickly see where you've gone wrong.
I would suggest that you also look at the output of this:
i = 1234
fliplr(i) %is the output 1234 or 4321? Did you expect that?
I would also suggest that you look up how to convert number into char arrays using either num2str or sprintf or into strings using string.