Skip to content

Instantly share code, notes, and snippets.

@ABD-01
Created April 21, 2020 11:31
Show Gist options
  • Save ABD-01/9a43752ca5c336b81b8d13f85c0b39ca to your computer and use it in GitHub Desktop.
Save ABD-01/9a43752ca5c336b81b8d13f85c0b39ca to your computer and use it in GitHub Desktop.
Write a recursive solution to print reverse of a number.
#include <stdio.h>
#include <math.h>
int reverse(int );
int main()
{
int num;
printf("Enter a num: ");
scanf(" %i",&num);
printf("The reverse of given integer is: %i \n",reverse(num));
return 0;
}
int reverse(int x)
{
if(x==0)
return 0;
int dig=log10(x);
return (x%10)*pow(10,dig) + reverse(x/10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment