Skip to content

Instantly share code, notes, and snippets.

@aligalehban
Created June 21, 2018 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aligalehban/fd7f2d5c4bef92c1ca39ed4563c6fe54 to your computer and use it in GitHub Desktop.
Save aligalehban/fd7f2d5c4bef92c1ca39ed4563c6fe54 to your computer and use it in GitHub Desktop.
Reverse number in c++ source code - www.alighalehban.com
#include <iostream>
using namespace std;
int main()
{
int n, reversedNumber = 0, remainder;
cout << "Enter an integer: ";
cin >> n;
while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}
cout << "Reversed Number = " << reversedNumber;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment