151. C Program to Reverse the given numbers using recursion.
How does this program work?
- In this C programme you will learn about how to reverse the given numbers using recursion.
Here is the code
#include <stdio.h>
int reverse(int num);
int main()
{
int num, rev;
//User input
printf("Enter any number: ");
scanf("%d", &num);
//Recursive funciton
rev = reverse(num);
printf("Reverse of %d = %d", num, rev);
//Display the output
return 0;
}
//Recursive function to find reverse of any number
int reverse(int num)
{
// Find total digits in num
int digit = (int) log10(num);
// Base condition
if(num == 0)
return 0;
return ((num%10 * pow(10, digit)) + reverse(num/10));
}