编写一个递归函数,将一个正整数的每一位取出来并从低位到高位的顺序输出。
思路:这道题不难,不断取位数将此数不断%10并除十调用函数。
代码:
#include<iostream>
using namespace std;
void reverse(int t);
int main(){
int a=0;
cin>>a;
reverse(a);
return 0;
}
void reverse(int t){
if(t/10==0)
{
cout<<t;
}
else
{
reverse(t%10);
reverse(t/10);
}
}