uses a while loop and if else statement to print all the palindrome numbers between 10 and 999 without using strnum and fliplr in matlab

Here's an example code that uses a while loop and if else statement to print all the palindrome numbers between 10 and 999 without using strnum and fliplr functions in MATLAB:

main.m
n = 10; % starting number
while n < 1000
    % extract each digit of the number
    a = floor(n/100); 
    b = floor(mod(n,100)/10); 
    c = mod(n,10);
    
    % check if the number is palindrome
    if a == c
        fprintf('%d is a palindrome number\n', n);
    end
    
    n = n + 1; % increment to next number
end
322 chars
15 lines

This code starts from the number 10 and iterates through all the numbers up to 999. Inside the while loop, each number is decomposed into its three digits (i.e., hundreds, tens, and units) using floor and mod functions. Then, the digits are compared to determine if the number is a palindrome. If the first and last digits are equal, then the number is a palindrome and it is printed to the console using fprintf function.

Note that this code is not the most efficient way to solve the problem and it is recommended to use vectorization or other MATLAB built-in functions for better performance.

related categories

gistlibby LogSnag