反转数字345 => 543使用matlab [英] reverse a number 345 => 543 using matlab
本文介绍了反转数字345 => 543使用matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用matlab并试图反转一个数字,使用下面的代码:
im using matlab and trying to reverse a number, using the code below:
function rnum = reverse(num)
rnum=0;
while(num>0)
m= mod(num,10);
rnum = rnum * 10 + m;
num = num /10;
end
end
i get:
i get :
ans =
Inf
我该如何修理它?获得真正的转发?
how can i fixe it? and get the true resault?
推荐答案
快速谷歌搜索我发现了这个,
将数字转换为string:
num2str(123)
使用fliplr:
fliplr(num2str(123))
A quick google search i found this,
Transform number into string:
num2str(123)
Use fliplr:
fliplr(num2str(123))
至少这个工作:
at least this one worked:
function rev = reverse(num)
rev=0;
while(num>1)
m= mod(num,10);
rev = floor(rev * 10 + m);
num = num /10;
%-----display situation each turn
disp(num);
end
end
这篇关于反转数字345 => 543使用matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文