How to reverse a number?

7 vues (au cours des 30 derniers jours)
Jessica
Jessica le 18 Nov 2014
Hi,
I want to reverse a number without using MATLAB functions "digitrevorder()" and "fliplr()". Please help. Thank you!

Réponses (3)

Evan
Evan le 18 Nov 2014
x = 1234;
s = num2str(x) - '0';
xr = polyval(s(end:-1:1),10)
  7 commentaires
John D'Errico
John D'Errico le 18 Nov 2014
Modifié(e) : John D'Errico le 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.
Guillaume
Guillaume le 18 Nov 2014
Modifié(e) : Guillaume le 18 Nov 2014
You also want to disallow rot90, flipud and flip, otherwise it's also trivial.

Connectez-vous pour commenter.


Syed Haider
Syed Haider le 18 Nov 2014
A = [1 2 3 4; 5 6 7 8];
y = A(:,end:-1:1)
  3 commentaires
Syed Haider
Syed Haider le 18 Nov 2014
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 le 18 Nov 2014
I don't see any reason to remove it.

Connectez-vous pour commenter.


saurabh jare
saurabh jare le 7 Mar 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

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by