How to reverse a number?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I want to reverse a number without using MATLAB functions "digitrevorder()" and "fliplr()". Please help. Thank you!
0 Kommentare
Antworten (3)
Evan
am 18 Nov. 2014
x = 1234;
s = num2str(x) - '0';
xr = polyval(s(end:-1:1),10)
7 Kommentare
John D'Errico
am 18 Nov. 2014
Bearbeitet: John D'Errico
am 18 Nov. 2014
A moderately interesting question is to find a solution in one line, without needing to form an intermediate variable. (And without the application of fliplr!) Seems trivial with that function.
Syed Haider
am 18 Nov. 2014
A = [1 2 3 4; 5 6 7 8];
y = A(:,end:-1:1)
3 Kommentare
Syed Haider
am 18 Nov. 2014
Yeah you are right :) I am sorry. Should i remove the answer? or may be it will be helpful for someone.
saurabh jare
am 7 Mär. 2023
function ran=reverse_number(x)
%x=input('Enter the value for checking the palindromic= \n');
check=x;
ran=0;
while (check~=0)
ran=(ran*10)+mod(check,10);
check=fix(check/10);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!