#include "stdio.h"
int reverse(int number)
{
int res = 0;
while(number)
{
res = res * 10 + number % 10;
number /= 10;
}
return res;
}
void main()
{
int num;
printf("input a number : ");
scanf("%d", &num);
printf("before reverse : %d\n", num);
printf("after reverse : %d\n", reverse(num));
}
function y = reverse(number)
yy = num2str(number);
yy_len = length(yy);
for i = 1:yy_len
yy1(i) = yy(yy_len-i+1);
end
y = str2num(yy1);
在命令窗口输入
y = reverse(123)
得到
y=321