C Program to Reverse Number using Recursion

C Program to Reverse Number using Recursion:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
    long n,a;
    long rev(long);
    printf("Enter a number more than 1 digit to find reverse \n");
    scanf("%ld",&n);
    a=rev(n);
    printf("Reverse of %ld is %ld",n,a);
}
int r=0,rem;
long rev(long n)
{

    if(n>0)
    {
        rem=n%10;
        r=r*10+rem;
        return(rev(n/10));
    }
    else
     return(r);
}

OUTPUT:

Enter a number more than 1 digit to find reverse
1475
Reverse of 1475 is 5741

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.