c program to find reverse of a number using recursion

#include<stdio.h>
#include<conio.h>
int reverse(int num); 
void main()
{
   int num, r=0;
   printf("n Enter a number: ");
   scanf("%d",&num);
   r = reverse(num);
   printf("n Reverse number = %d",r);
   getch();

} 
int rev = 0, rem = 0;  
int reverse(int num)
{
   if(num)   {
     rem=num%10;
     rev=rev*10+rem;
     reverse(num/10);
   }
   return rev;
} 

Ouput:

Enter a number: 371
Reverse number = 173

 

Leave a Reply

error: Content is protected !!
%d bloggers like this: