Skip to content

Instantly share code, notes, and snippets.

@peteonrails
Created January 10, 2012 15:47
Show Gist options
  • Save peteonrails/1589714 to your computer and use it in GitHub Desktop.
Save peteonrails/1589714 to your computer and use it in GitHub Desktop.
Reverse an Integer in C
// 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