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/c94b2e70393326aeb10a5cb471ea4ff9 to your computer and use it in GitHub Desktop.

Select an option

Save mohnoor94/c94b2e70393326aeb10a5cb471ea4ff9 to your computer and use it in GitHub Desktop.
Reverse Any Integer C++ Full Program | AbuKhleif
// www.abukhleif.com
#include <iostream>
using namespace std;
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;
}
int main() {
cout<<reverseDigit(-12345);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment