show us palindrome numbers using while and if else in matlab

Here's an example code that shows palindrome numbers using a While loop and If-Else statements in Matlab:

main.m
% Prompt user to enter range of numbers
startNum = input('Enter starting number: ');
endNum = input('Enter ending number: ');

% Check each number in the range
while (startNum <= endNum)
    % Convert number to string
    numStr = num2str(startNum);
    
    % Check if the string is equal to its reverse
    if (strcmp(numStr, fliplr(numStr)))
        disp(startNum);
    end
    
    % Increment the number
    startNum = startNum + 1;
end
442 chars
18 lines

In this code, the user is prompted to enter the starting and ending numbers to check for palindrome numbers within that range. The While loop iterates through each number in the range and converts it to a string using num2str. The If-Else statement checks if the string is equal to its reverse (found using fliplr) and if so, prints out the number using disp. Finally, the number is incremented by 1 and the loop continues until the end of the range is reached.

gistlibby LogSnag