Created
January 10, 2012 15:47
-
-
Save peteonrails/1589714 to your computer and use it in GitHub Desktop.
Reverse an Integer in C
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
// I am not sure why I get asked to do this so frequently, | |
// but here is how I do it. | |
#include <stdio.h> | |
int main () { | |
int backwards = 0; | |
int value = 12345678; | |
int orig = value; | |
do | |
backwards = (backwards * 10) + (value % 10) ; | |
while ( value = value / 10 ) ; | |
printf("Value : %d, Backwards: %d", orig , backwards); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment