How to reverse a number?

4 次查看(过去 30 天)
Jessica
Jessica 2014-11-18
Hi,
I want to reverse a number without using MATLAB functions "digitrevorder()" and "fliplr()". Please help. Thank you!

回答(3 个)

Evan
Evan 2014-11-18
x = 1234;
s = num2str(x) - '0';
xr = polyval(s(end:-1:1),10)
  7 个评论
John D'Errico
John D'Errico 2014-11-18
编辑:John D'Errico 2014-11-18
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.
Guillaume
Guillaume 2014-11-18
编辑:Guillaume 2014-11-18
You also want to disallow rot90, flipud and flip, otherwise it's also trivial.

请先登录,再进行评论。


Syed Haider
Syed Haider 2014-11-18
A = [1 2 3 4; 5 6 7 8];
y = A(:,end:-1:1)
  3 个评论
Syed Haider
Syed Haider 2014-11-18
Yeah you are right :) I am sorry. Should i remove the answer? or may be it will be helpful for someone.
John D'Errico
John D'Errico 2014-11-18
I don't see any reason to remove it.

请先登录,再进行评论。


saurabh jare
saurabh jare 2023-3-7
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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by