Recursively realize the reverse order of outputting an integer

mission details

Write a recursive function to output an integer n in reverse order, for example, n = 12345, and output 54321.

test introduction

Sample input:

12345

Sample output

54321

code show as below:

#include<stdio.h>
void solve(int n)
{
    
    
   if(n<10)
   {
    
    
   	printf("%d",n);
   }
   else
   {
    
    
   	printf("%d",n%10);
   	return solve(n/10);
   }
}
int main(void)
{
    
    
    int n;
    scanf("%d",&n);
    solve(n);
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_51705589/article/details/112981898