Created
April 21, 2020 11:31
-
-
Save ABD-01/9a43752ca5c336b81b8d13f85c0b39ca to your computer and use it in GitHub Desktop.
Write a recursive solution to print reverse of a number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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