Skip to content

Instantly share code, notes, and snippets.

@mohnoor94
Last active August 20, 2017 21:13
Show Gist options
  • Select an option

  • Save mohnoor94/f0fc46b16828533396a9acfcfbb431f0 to your computer and use it in GitHub Desktop.

Select an option

Save mohnoor94/f0fc46b16828533396a9acfcfbb431f0 to your computer and use it in GitHub Desktop.
Reverse Any Integer C++ Function | AbuKhleif
// www.abukhleif.com
int reverseDigit (int num){
bool isNegative = false;
if (num < 0){
isNegative = true;
num = -1 * num;
}
int reversedNumber = 0;
while (num > 0){
int d = num % 10;
reversedNumber = reversedNumber * 10 + d;
num /= 10;
}
return (isNegative) ? -1 * reversedNumber : reversedNumber;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment