Here is a solution in MATLAB that uses a while loop and if else statement to print all the palindrome numbers between 10 and 999:
main.m121 chars8 lines
First, we initialize num
to 10. Then, we use a while loop to iterate from 10 to 999. Inside the loop, we convert the number to a string using num2str
, reverse the order of the characters using fliplr
, and then convert back to a number using str2num
. If the resulting number is equal to the original number, then the number is a palindrome and we use disp
to print it to the console. Finally, we increment num
to move on to the next number in the iteration.
Note that there are more efficient ways to check for palindromes using MATLAB built-in functions. However, this solution uses only while loops and if else statements as requested in the question.
gistlibby LogSnag