先上自写的代码
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
void reverse(long int x)
{
if (x / 10 == 0)
{
cout << x;
return;
}
else
{
cout << x % 10;
reverse(x / 10);
}
}
int main()
{
long int x;
cin >> x;
if (x < 0)
{
cout << "-";
x *= -1;
}
while(x % 10 == 0)
{
x /= 10;
}
reverse(x);
return 0;
}
再贴几个入门的递归关于数字输出的帖子(转载)
1:https://blog.csdn.net/richard1997/article/details/79255784
2:https://blog.csdn.net/qq_30252385/article/details/84670274