How to reverse a number?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I want to reverse a number without using MATLAB functions "digitrevorder()" and "fliplr()". Please help. Thank you!
댓글 수: 0
답변 (3개)
Evan
2014년 11월 18일
x = 1234;
s = num2str(x) - '0';
xr = polyval(s(end:-1:1),10)
댓글 수: 7
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.
Syed Haider
2014년 11월 18일
A = [1 2 3 4; 5 6 7 8];
y = A(:,end:-1:1)
댓글 수: 3
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.
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!