c++ backward integer
Go to solution
Solved by Nineshadow,
@WildCAt It's pretty simple.
int rev(int n){ int x = 0; while(n) { x = x * 10 + n%10; n/=10; } return x;}
Do you understand how it works?
You initialize your new backward number to 0. Then, you make your new number itself times 10 (to make place for another digit) , then add the last digit of the original number. Then you divide your original number by 10 to get to the next digit and you keep going on until the original number becomes 0.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now